Skip to content

Commit 9438116

Browse files
fix(logging): allow child loggers to set independent log levels
The handler's level was being set to the root logger's level in basicConfig(), which prevented child loggers from setting their own levels. This violated the standard logging architecture where handlers should not filter by level - that's the logger's responsibility. Changed handler.setLevel(level) to handler.setLevel(NOTSET) in basicConfig() so that handlers pass through all messages and let loggers control filtering. This allows code like: logger = logging.getLogger("myapp") logger.setLevel(logging.INFO) logger.info("message") # Now works correctly Previously, INFO messages would be filtered out if the root logger was at WARNING. Fixes: Child loggers unable to log at levels lower than root logger's level Signed-off-by: Thomas Farstrike <111072251+ThomasFarstrike@users.noreply.github.com>
1 parent 6ae440a commit 9438116

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

python-stdlib/logging/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def basicConfig(
242242
else:
243243
handler = FileHandler(filename, filemode, encoding)
244244

245-
handler.setLevel(level)
245+
handler.setLevel(NOTSET)
246246
handler.setFormatter(Formatter(format, datefmt))
247247

248248
logger.setLevel(level)

0 commit comments

Comments
 (0)