mCodingLLC / VideosSampleCode

Code from the mCoding sample videos
MIT License
952 stars 198 forks source link

Python dictConfig example config is inaccurate #17

Open FSund opened 5 months ago

FSund commented 5 months ago

This is not the correct way to configure the root logger. This configures the logger named "root", which is a child of the actual root logger. The effect is that logger = logging.getLogger("my_logger") does not use the configuration from the JSON (since "my_logger" is not a child of "root", but of the actual root logger, which has not been configured).

https://github.com/mCodingLLC/VideosSampleCode/blob/b6fe3c808c9a31b0425fe9f2005420fdb1958f0f/videos/135_modern_logging/logging_configs/2-stderr-json-file.json#L39-L47

The root logger uses a separate root key (source), so the correct JSON would be

  "loggers": {},
  "root": {
    "level": "DEBUG",
    "handlers": [
      "stderr",
      "file"
    ]
  }

(the empty "loggers" key can probably be skipped).