[Python-ideas] Logging2 with default NullHandler

anatoly techtonik techtonik at gmail.com
Thu Mar 15 23:39:48 CET 2012

On Fri, Mar 16, 2012 at 12:32 AM, Cameron Simpson <cs at zip.com.au> wrote:
> On 14Mar2012 21:28, anatoly techtonik <techtonik at gmail.com> 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.
> Fair point.
> Conversely, almost every app I write commences thus:
>  from cs.logutils import setup_logging
>  def main(argv):
>    setup_logging()
>    ... main code ...
> That sends to stderr with frills. Finer grained setup can come later.

But that makes all such libraries dependent on cs.logutils, which is
not an option. In my case these libraries are self-contained PySide
widgets that can be used standalone or from an IDE. Adding dependency
on cs.logutils makes them too tied to application.

> I _think_ I prefer logging's current behaviour:
>  - I do want a big fat warning if I forget to configure logging at all

Unless your application uses alternative logging means and doesn't use
logging at all (unlike 3rd party libraries it uses).

>  - I don't want lobraries doing sufficient work at import time to
>    warrant logging anything

I do not want libraries doing any logging setup work at import either.
They should just need to contain 'extension points' for plugging log
handlers in case I need to debug these modules.
anatoly t.

More information about the Python-ideas mailing list