logging from several independent classes

Sandy dksreddy at gmail.com
Wed Oct 28 07:35:34 EDT 2009


Hi all,
I was going through the last example in logging docs:
http://docs.python.org/library/logging.html#using-logging-in-multiple-modules

It explains how to log from multiple classes. The example works fine
as long as the logger names are in a heirarchy
(spam_application.auxiliary.Auxiliary, spam_application.auxiliary,
spam_application).
Just configure at top level and the child classes automatically
inherit the config. If I change the name that don't have any
heirarchy, it fails to log properly. My question is: Is it possible to
configure logging in the main script that calls different independent
classes (say A, B, C) and still the loggers in A, B, C inherit the
config from the main script?

For example in class A, all I want to do is
import logging
log = logging.getLogger("A")

and log should be configured according to who ever instantiates A.

Cheers,
Sandeep



More information about the Python-list mailing list