By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

logging package problems

P: n/a
I found that the configuration system of the new logging package of Python
2.3 has some
unintuitive idiosyncracies that are worth mentioning because they can cost
you quite some
development time and are not documented elsewhere.

I used the logging configuration file shown below. My aim was to log only
the INFO messages,
but log DEBUG messages for one particular module (called webTestLogin.py).

Here's what I found out:
- if your init logging in your module with the line
log = logging.getLogger()
then the logging module will determine the module where the call
originated and in your log files
you'll find lines like
2004-01-26 11:21:15,890 [INFO] creating ticket for this session
[in webtestlogin]
where webTestLogin mysteriously lost its capitalization. Now, this does
*not* mean that
webtestlogin will also be the 'qualname', i.e. the name of a channel
that you can use
to log messages from this module to a different place or in a different
manner; for that
to work, you'll need the following line of code:
log = logging.getLogger('webtestlogin')
(making 'webtestlogin' a channel, or some sort of logical logging unit
that allow its calls to be handled
differently from the other log calls in your program).
The documentation says qualname is the 'fully qualified name', but
doesn't contend on what
that is; I tried the complete package name, that didn't work
('com.cellzome.pandora.webTestLogin').
- capitalization *is* very important; if you use lowercase in the code,
you'll need lowercase
in the logging config file as well (see the qualname line below)
- 'propagate' forwards log messages to other loggers, so you may e.g. log
the same line to
two different places - so far so good. But: If you set propagate to 1 in
the [logger_webtestlogin]
shown below, the root logger will log DEBUG messages too, even though it
was told to log
only INFO - just because the message has been forwarded (?!?)
Generally I think that propagation follows the order of the loggers, but
I still don't get the
complete picture.
- the config file scanner/parser is not very robust; if you use spaces in
a list for aesthetic reasons
(e.g. keys=root, webtestlogin) the key list will be ('root', '
webtestlogin'). This can produce
quite esoteric errors :-)

Maybe I didn't get the point/purpose of the framework on some of those
issues, but
then again it might be worth to extend the existing documentation a bit.

Cheers,

Robert F Schmitt, Cellzome AG
Meyerhofstr. 1, D-69117 Heidelberg, Germany
Tel + 49 6221 137 57 405, Fax + 49 6221 137 57 202
www.cellzome.de
------------------------------------------------------------------------------------
The vast majority of our imports come from outside the country."
- George W. Bush

"If we don't succeed, we run the risk of failure."
- George W. Bush

///////////////////////////////////////////////////////////////////
/////////////// config file ///////////////
///////////////////////////////////////////////////////////////////

################################################## #########
# general references

[loggers]
keys=root,webtestlogin

[handlers]
keys=drogenHandler,stdoutHandler

[formatters]
keys=taschenFormat,textOnlyFormat

################################################## #########
# loggers

[logger_webtestlogin]
level=DEBUG
handlers=drogenHandler,stdoutHandler
propagate=0
qualname=webtestlogin

[logger_root]
level=INFO
handlers=drogenHandler,stdoutHandler
propagate=1

################################################## #########
# handlers

[handler_drogenHandler]
class=FileHandler
level=NOTSET
formatter=taschenFormat
args=('pandora.log', 'w')

[handler_stdoutHandler]
class=StreamHandler
level=INFO
formatter=textOnlyFormat
args=(sys.stdout,)

################################################## #########
# formatters

[formatter_taschenFormat]
format=%(asctime)s [%(levelname)s] %(message)s [in %(module)s]

[formatter_textOnlyFormat]
format=%(levelname)s %(message)s
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.