Quantcast
Channel: RasadaCrea rss feeds aggregator
Viewing all articles
Browse latest Browse all 176

Python Sweetness, Use of logging package from within a library

$
0
0
Python's standard logging package is a really wonderful thing, but unfortunately some of its key ideas aren't clearly documented in a large enough point font. Luckily most library authors seem to understand these ideas by default, however quite a few (particularly commercial) libraries seem to ignore them. If you're writing and distributing reusable libraries that use the logging package, please try to avoid: Logging to the root logger Ideally package-level convenience functions like logging.debug() wouldn't exist, since they're hard-wired to use the root logger. When library code emits messages via the convenience functions, no useful component name is included in the message, and so the user is forced to grep her site-packages directory to try and find the culprit of a strange looking message. Library code should *always* log to a private logger instance, which will percolate up the root anyway, except the message will be nicely tagged and organized so the application author can selectively disable (or enable!) logging for your code. If everything logs to the root logger, then one of the primary benefits of the logging package is lost: selectively controllable hierarchical logging contexts. A better approach is something .. cntd

Viewing all articles
Browse latest Browse all 176

Trending Articles