Mario Corchero

Authored Comments

Even if you can log using the module level functions (logging.info) that is basically just logging with the root logger.

You can see doing `logging.info` identical to `logging.getLogger().info` it just logs under the root instance.

With that said the question becomes: is there any advantage of not using always the root logger?
The answer is tuning. If you are developing a single script is probably fine (I do it quite often) but if you are developing a larger program or a library you definitively want to use different loggers so at the time when you set up your configuration you can decide what to do with the logs coming from that piece of code.

As an example, if you develop an http library and log everything on info, using the logger hierarchy allows the users of your library to just suppress all info logs by configuring your root logger to emit only records above info.

You can also attach different handlers and tune accordingly.

In brief, my take is:
For simple scripts probably ok, for more complex solutions always go to proper logger instances.

And thank you for reading it :)

Thank you for reading it :)