Two questions about logging
Jean-Michel Pichavant
jeanmichel at sequans.com
Thu Jan 12 05:28:55 EST 2012
Matthew Pounsett wrote:
> [snip]
>
> Second, I'm trying to get a handle on how libraries are meant to
> integrate with the applications that use them. The naming advice in
> the advanced tutorial is to use __name__ to name loggers, and to allow
> log messages to pass back up to the using application's logger for
> processing, but these two pieces of advice seem contradictory.. since
> log messages only pass back up to the root if the loggers are named
> hierarchically.
>
> [snip]
>
> So, given this state of affairs, how is a library author to use
> loggers, given that he or she can't know how authors who use the
> library will name their logger objects? In the above example, what
> would the author of bar.py do to hook up bar's logger with foo's,
> without knowing in advance what foo's logger will be named?
>
>
> Thanks very much for any suggestions, or pointers to documentation
> that I've missed.
>
All loggers share at least one parent : the root logger. In the standard
way of using the loggers, the root logger is *the* logger responsible of
processing logs.
Considering that extlib is an external library from anApp, and intlib an
internal library to the anApp application:
People may expect logs that way:
anApp.extlib : INFO : a log message
anApp.intlib : INFO : another message
However, what will happen is :
extlib : INFO : message from the external lib
anApp.intlib : INFO : message from the internal lib
As you mentioned in your post, there is no way to 'attach' an external
lib to your application since the external lib knows nothing about the
application, but there is no need to attach it actually.
JM
More information about the Python-list
mailing list