[Python-ideas] Logging2 with default NullHandler

anatoly techtonik techtonik at gmail.com
Thu Mar 15 16:54:24 CET 2012


On Thu, Mar 15, 2012 at 3:24 PM, Niki Spahiev <niki.spahiev at gmail.com> wrote:
> On 14.03.2012 21:28, anatoly techtonik wrote:
>>
>> Badly need `logging2` module that has NullHandler assigned by default
>> for all loggers.
>> http://packages.python.org/Logbook/api/handlers.html#logbook.NullHandler
>>
>> Why? Because logging fails to play well with libraries:
>>
>>    import logging
>>    log = logging.getLogger(__name__)
>>    log.warn("WARN")
>>
>>    No handlers could be found for logger "spyderlib.utils.bsdsocket"
>>
>> What do I want from library logging as a Python application developer?
>> Nothing until I explicitly setup default behaviour.
>>
>> logging can not be changed, and leaving everything as-is is a PITA,
>> that's why I am
>> proposing for logging2 as the only viable solution.
>
>
> Can't this be solved with new function? e.g.
>  log = logging.getLibLogger(__name__)

I don't know - there are questions. The function is used to get logger
with NullHandler() if application did not provide configuration for
root logger. So..

1. How will logging know that application provided root logger configuration?
2. How will logging know that it should use root logger handler
instead of more specific handler for __name__ module?

This comes to the second part - what if logging.getLibLogger(__name__)
is called after the application root handler is configured?

1. Will a new, more specific NullHandler() override the active root
configuration?

There is one more concern. If anything in the code base (including 3rd
party modules) calls logging.log() or friends before root logger is
configured by application, the root logger becomes automatically
configured making everything above useless.

--
anatoly t.



More information about the Python-ideas mailing list