How to implement logging for an imported module?

Pankaj Jangid pankaj at codeisgreat.org
Sun Mar 7 22:48:25 EST 2021


"Joseph L. Casale" <jcasale at activenetwerx.com> writes:

>> I couldn't find any information on how to implement logging in a
>> library that doesn't know the name of the application that uses
>> it. How is that done?

> Create (get) a root logger (you don't have to use it) and set the
> level, and attach a handler to it. Then get the logger your library
> uses and set the level to what you want.

So does that mean if we change the following code to get a logger
without any name then it will work? Without any further change.

>> logger = logging.getLogger('foo')
>> logger.addHandler(ch)
>> logger.setLevel(logging.DEBUG)

-- 
Regards,
Pankaj Jangid




More information about the Python-list mailing list