Re: logging from several independent classes

2009-10-29 Thread Sandy

 All named loggers (including A, B etc.) inherit from the root logger,
 obtained by doing

 root_logger = logging.getLogger()

 or

 root_logger = logging.getLogger()

Somehow I missed this in the docs.
Thanks Vinay.

-- 
http://mail.python.org/mailman/listinfo/python-list


logging from several independent classes

2009-10-28 Thread Sandy
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: logging from several independent classes

2009-10-28 Thread Vinay Sajip
Sandy dksreddy at gmail.com writes:

 
 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

The documentation you pointed to is about logging from multiple modules. Are you
sure you understand the distinction between classes and modules?

 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)

All named loggers (including A, B etc.) inherit from the root logger,
obtained by doing

root_logger = logging.getLogger()

or

root_logger = logging.getLogger()

So you can use that to configure your handlers, level etc.

Regards,

Vinay Sajip


-- 
http://mail.python.org/mailman/listinfo/python-list