473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

logging package problems

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
0 1630

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Logan | last post by:
Is there actually a good reason why the StreamHandler and the FileHandler are in the core package and all other handlers are in logging.handlers? I first did not realize this when reading the...
0
by: Robert.Schmitt | last post by:
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...
3
by: Jeff Shannon | last post by:
I'm having some difficulty getting my logging configuration set correctly. I'm using a config file (copied at end of post), with the intent of setting several loggers which write to a combination...
1
by: j vickroy | last post by:
My system: MSW XP professional Python 2.3.3 logging package: 0.4.9.2 My problem: The log_test3.py script, provided with the logging package distribution, generates an unexpected message: No...
23
by: Rotem | last post by:
Hi, while working on something in my current project I have made several improvements to the logging package in Python, two of them are worth mentioning: 1. addition of a logging record field...
0
by: skip | last post by:
We use the standard logging package and frequently bump into performance issues with it (we log a lot of information). When that happens, we then go through our code and dump a bunch of logging...
1
by: nicholas.farrell | last post by:
Hi everyone. I've just been trying to add a bit more granularity to my logging code, as the jump from INFO (level 20) to DEBUG (level 10) is a bit too big. I was thinking of borrowing a few...
2
by: Vinay Sajip | last post by:
Some users of the logging package have raised an issue regarding the difficulty of passing additional contextual information when logging. For example, the developer of a networked application may...
4
by: Matthew Wilson | last post by:
I'm working on a package that uses the standard library logging module along with a .cfg file. In my code, I use logging.config.fileConfig('/home/matt/mypackage/matt.cfg') to load in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.