[Python-ideas] Logging2 with default NullHandler
cs at zip.com.au
Fri Mar 16 03:10:54 CET 2012
On 16Mar2012 00:39, anatoly techtonik <techtonik at gmail.com> wrote:
| > | 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.
No, it doesn't. setup_logging just sets up the root logger somewhat.
Your apps need some kind of convenience routine like it, is all.
It can be very small.
All the libraries have unchanged vanilla logging calls.
For example, I use SQLalchemy et al under this scheme. The libraries
don't know about cs.logutils at all.
| 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.
The libraries don't use my convenience module. My module just makes a whole
bunch of setup I happen to like reduce to just two lines of code in my app,
import and setup call.
| > 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).
If the 3rd party libraries use the logging module and you don't want
logging happening, just configure logging to throw stuff away.
| > - 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.
Well, they do. Via logging. Supply an adapter handler to hook their
calls to logging to your alternative logging means. Logging doesn't have
to log to files/syslog/smtp etc - you can sent it anywhere. I'm sure you
know that, so I think I'm missing some subtlety in your use case.
Cameron Simpson <cs at zip.com.au> DoD#743
ERROR 155 - You can't do that. - Data General S200 Fortran error code list
More information about the Python-ideas