logging module question

Vinay Sajip vinay_sajip at yahoo.co.uk
Wed Jan 25 10:12:02 EST 2006


> but now I'd like to understand the design rational behind having each
> logger in the object hierarchy log the same output by default.  Anyone?

Loggers are different to handlers. Loggers map to areas of the
application, handlers map to output destinations. Loggers form a
hierarchy based on names - "myapp" is a parent logger of
"myapp.archiving" or "myapp.workflow", for example. All loggers are
descendants of a root logger.

Logging events are not passed to all loggers, but are by default passed
to the handlers of the logger which logs the event, and then up the
hierarchy to the handlers of ancestor loggers. Both handlers and
loggers can be set to filter by level, or (by using Filters) can filter
according to custom criteria. You can also use custom Formatters to
format the output - for example, a formatter which does not send
traceback information to the output can be set (for a particular
handler).

See PEP 282 for background information on the logging scheme. You can
also look at Apache logging (log4j, log4net etc.) and java.util.logging
which adopt a similar approach (experience having shown that this is a
good approach).

Regards,

Vinay Sajip




More information about the Python-list mailing list