pygreynoise icon indicating copy to clipboard operation
pygreynoise copied to clipboard

do not setup logging in library code

Open guzzijones opened this issue 2 years ago • 3 comments

https://github.com/GreyNoise-Intelligence/pygreynoise/blob/c1fc4f4eae47e2eec1a2e3b0b487f7d88b4fdf79/src/greynoise/api/init.py#L17

This is a big no no. logging should be setup by the user of the module not the module itself. Use:

logger = logging.getLogger(___name__)

guzzijones avatar Aug 17 '22 14:08 guzzijones

https://docs.python.org/3.7/howto/logging.html#library-config

read the NOTE section.

guzzijones avatar Aug 17 '22 14:08 guzzijones

Note It is strongly advised that you do not add any handlers other than NullHandler to your library’s loggers. This is because the configuration of handlers is the prerogative of the application developer who uses your library. The application developer knows their target audience and what handlers are most appropriate for their application: if you add handlers ‘under the hood’, you might well interfere with their ability to carry out unit tests and deliver logs which suit their requirements.

guzzijones avatar Aug 17 '22 14:08 guzzijones

Thanks for the note @guzzijones : I will review it and see what we can do.

bradchiappetta avatar Aug 17 '22 14:08 bradchiappetta

@guzzijones : I've got some WIP changes in branch v1.3.0_updates. Feel free to comment if you think this covers what you requested with this fix.

bradchiappetta avatar Sep 06 '22 20:09 bradchiappetta