Logging Config – in code vs in config file

The built-in logging module of python 3.x allows for 3 ways to define a custom logger:

  1. INI-formatted file
  2. dict, json, yaml
  3. python (directly in code)

In my opinion, it is easier to define a custom logger’s config directly in the code, because this does not require anyone to understand other formats (it is not obvious what the dependencies are in INI, yaml, and json formats). If config is written in python, then any coder can understand how the Formatter, Handler, and Logger relate to each other programmatically, if not conceptually.

Are there reasons why it is better to define the logging config in a separate config file? I’m guessing this would have to do with wanting multiple deploys with different logging levels, but I can’t imagine a compelling use case for this.