Skip to content

Commit 6e8bc9a

Browse files
committed
[fix] Fix migration logging
Python "logging" module handles a hierarchy of loggers. Loggers can be given handlers to handle the actual log message. If a logger doesn't have a handler then the parent's handler will be used. "logger.handlers" is an array containing the direct handlers, but "logger.hasHandlers()" returns true even if the parent has a handler. So, the array can be empty and "hasHandlers()" still returns True.
1 parent 0bbf351 commit 6e8bc9a

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

  • web/server/codechecker_server/migrations

web/server/codechecker_server/migrations/logging.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ def setup_logger(schema: str):
6363
logger = logging.getLogger(f"migration/{schema}")
6464
logging.setLoggerClass(existing_logger_cls)
6565

66-
if not logger.hasHandlers():
66+
# logger.hasHandlers() falls back on parent's handlers, however,
67+
# logger.handlers contains the immediate handlers only. It is important to
68+
# check this list directly otherwise list indexing fails on "else" branch.
69+
if not logger.handlers:
6770
fmt = MigrationFormatter(schema)
6871
handler = logging.StreamHandler()
6972
handler.setFormatter(fmt)

0 commit comments

Comments
 (0)