python icon indicating copy to clipboard operation
python copied to clipboard

Logging setup violates best practices

Open mdecuir opened this issue 1 year ago • 0 comments

I just ran into an issue when adding ipdata as a library used by my project that the log outputs I received suddenly changed formatting. Upon digging into the issue, I found that the ipdata library calls logging.basicConfig to set a RichHandler instance for the root logger if one is not otherwise defined. It then writes its logs to a logger named "rich".

This violates several of python's best practices regarding configuring logging within a library: https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library

In particular, the issue that is causing problems for my application is that the app does not define any handlers on the root logger, but when we started using ipdata, all of a sudden logs from all of our 3rd party libraries were showing up in our log and in strange formats, resulting in further downstream frustrations.

To be compliant with python best practices, I believe that the logging.basicConfig call should be removed from the ipdata library and the logger name used by the library should be updated to __name__ .

mdecuir avatar Nov 07 '23 14:11 mdecuir