Logging to zero or more destinations

samwyse samwyse at gmail.com
Tue Jul 8 08:26:01 EDT 2008


In the Python 2.5 Library Reference, section 14.5.3 (Logging to
multiple destinations), an example is given of logging to both a file
and the console.  This is done by using logging.basicConfig() to
configure a log file, and then calling
logging.getLogger('').addHandler(console) to add the console.

However, in section 14.5.4 (Sending and receiving logging events
across a network), a call is made to
rootLogger.addHandler(socketHandler), and later it is stated that "On
the client side, nothing is printed on the console".

Finally, back in section 14.5.2 (Basic example), it's stated that "by
default, the root logger is configured to only handle messages with a
severity of WARNING or above. The message format is also a
configuration default, as is the output destination of the messages -
sys.stderr."

The only way that I can see for all three statements to be consistent
is that the root logger starts with an empty list of handlers, and
doesn't instantiate a default handler until either
logging.basicConfig()  is called, or the first time that a message is
logged.  This would also seem to imply that there's no way to use an
empty handler list (say, if you want to suppress all logging), because
the root handler will instantiate a handler for you.  Is this correct?

P.S.  I tried researching this further by myself, but the logging
module doesn't come with source (apparently it's written in C?) and I
don't have the time to find and download the source to my laptop.

Thanks!



More information about the Python-list mailing list