473,508 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1645

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

Similar topics

0
1334
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
318
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
5261
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
3681
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
2187
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
1178
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
1452
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
1954
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
2354
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
7382
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...
1
7042
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.