473,722 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Logging with multiple loggers/handlers

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 of a
file, stderr (for debugging), and the NT Eventlog, but I don't seem to
be getting the right combination of handlers called.

The desired combinations are as follows:

root - Eventlog, stderr
log02 - file, stderr
log02.log03 - file, stderr
log02.log04 - Eventlog, file, stderr

Currently, logging to stderr is working for all four loggers, but only
log02 is being written to the logfile. Also, log03 is writing to the
Eventlog even though it shouldn't be reaching that handler at all.

Any suggestions as to how I could change my logconfig.ini to get the
desired effect? (I'm considering creating an 'init' logger off of the
root, which would handle the Eventlog records, thus allowing me to
propagate all the stderr records to root, but this doesn't seem like
it'd directly affect the parts I'm having problems with...)

For reference, I'm using Python 2.2.1 and v0.4.9.2 of the logging
package. (Upgrading to a newer version of Python is not preferred,
though it could be done if it'll resolve the problem, but I've gathered
that the logging package *should* work fine with Py2.2.)

Jeff Shannon
Technician/Programmer
Credit International

----- logconf.ini -------------------------
[loggers]
keys=root,log02 ,log03,log04

[handlers]
keys=hand01,han d02,hand03

[formatters]
keys=form01

[logger_root]
level=NOTSET
propagate=1
channel=
parent=
qualname=(root)
handlers=hand01 ,hand03

[logger_log02]
level=DEBUG
propagate=0
channel=log02
parent=(root)
qualname=log02
handlers=hand02 ,hand03

[logger_log03]
level=DEBUG
propagate=1
channel=log03
parent=log02
qualname=log02. log03
handlers=

[logger_log04]
level=DEBUG
propagate=1
channel=log04
parent=log02
qualname=log02. log04
handlers=hand01

[handler_hand01]
class=handlers. NTEventLogHandl er
level=DEBUG
formatter=form0 1
appname=LogTest
dllname=
logtype=Applica tion
args=('LogTest' , '', 'Application')

[handler_hand02]
class=FileHandl er
level=DEBUG
formatter=form0 1
filename=Logs\p ython.log
mode=a
args=('Logs\pyt hon.log', 'a')

[handler_hand03]
class=StreamHan dler
level=DEBUG
formatter=form0 1
stream=sys.stde rr
args=(sys.stder r,)

[formatter_form0 1]
format=%(asctim e)s %(name)s %(levelname)s %(message)s
datefmt=

Jul 18 '05 #1
3 5275
To follow up to my own post -- I've found my problem, and it appears to
have been between my ears. ;P

I somehow managed to misinterpret the spec for logging.getLogg er().
From the current docs:

getLogger([name]):
Return a logger with the specified name or, if no name is specified,
return
a logger which is the root logger of the hierarchy.

All calls to this function with a given name return the same logger
instance.
This means that logger instances never need to be passed between
different
parts of an application.

Combined with this bit from PEP 282:
Loggers are never instantiated directly. Instead, a module-level
function is used:

def getLogger(name= None): ...

If no name is specified, the root logger is returned. Otherwise,
if a logger with that name exists, it is returned. If not, a new
logger is initialized and returned. Here, "name" is synonymous
with "channel name".

And the descriptions of the config file
(http://www.red-dove.com/python_logging.html#config):

#The channel value indicates the lowest portion of the channel name
of the
#logger. For a logger called "a.b.c", this value would be "c".

All of this combined to give me the impression that the name that's
passed to getLogger() should be the "lowest portion" channel name,
rather than the fully qualified name -- i.e., that I should be using
"log03" instead of "log02.log0 3". As it turns out, my impression was
wrong -- it's the fully qualified name that should be used. My attempts
to use the unqualified name were creating new, unconfigured loggers
(with no handlers attached) that could only propagate records up to the
root logger. I realized this only after inspecting the log manager's
loggerDict and seeing the unconfigured "extra" loggers.

While it's fairly likely that my interpretation of the docs is not
something that many people will come up with, I think it might be
worthwhile to expand the example sections to actually show how to use
multiple heirarchical loggers. Had there been an example to follow, I
certainly wouldn't have made this mistake.

Jeff Shannon
Technician/Programmer
Credit International
Jul 18 '05 #2
> Loggers are never instantiated directly. Instead, a module-level
function is used:

def getLogger(name= None): ...

If no name is specified, the root logger is returned. Otherwise,
if a logger with that name exists, it is returned. If not, a new
logger is initialized and returned. Here, "name" is synonymous
with "channel name".

And the descriptions of the config file
(http://www.red-dove.com/python_logging.html#config):

#The channel value indicates the lowest portion of the channel name
of the
#logger. For a logger called "a.b.c", this value would be "c".

All of this combined to give me the impression that the name that's
passed to getLogger() should be the "lowest portion" channel name,
rather than the fully qualified name -- i.e., that I should be using
"log03" instead of "log02.log0 3". As it turns out, my impression was
wrong -- it's the fully qualified name that should be used. While it's fairly likely that my interpretation of the docs is not
something that many people will come up with, I think it might be
worthwhile to expand the example sections to actually show how to use
multiple heirarchical loggers. Had there been an example to follow, I
certainly wouldn't have made this mistake.


The example in http://www.red-dove.com/python_logging.html#config does
show in bold the items used by the configuration API, and says that
the others are just used by the GUI configurator. Perhaps "channel"
was the wrong name to use for a private element in the configurator,
but it's done now.
Jul 18 '05 #3
Vinay Sajip wrote:
While it's fairly likely that my interpretation of the docs is not
something that many people will come up with, I think it might be
worthwhile to expand the example sections to actually show how to use
multiple heirarchical loggers. Had there been an example to follow, I
certainly wouldn't have made this mistake.


The example in http://www.red-dove.com/python_logging.html#config does
show in bold the items used by the configuration API, and says that
the others are just used by the GUI configurator. Perhaps "channel"
was the wrong name to use for a private element in the configurator,
but it's done now.


May I suggest changing the wording of the getLogger() docs? I think
that simply adding a few words to a single sentence will clarify things
considerably.

- Here, "name" is synonymous with "channel name".
+ Here, "name" is synonymous with "fully qualified channel name".

Jeff Shannon
Technician/Programmer
Credit International

Jul 18 '05 #4

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

Similar topics

0
1659
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 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).
2
2217
by: chuck | last post by:
I want to create two different loggers so that users see one output (e.g. no exception/stack traces) and others (e.g support staff) that does see stack traces via email. The code below is close but I still get console output on the email logger from the "root" logger. How do I get rid of it? import logging import logging.handlers
1
3091
by: Rene Pijlman | last post by:
I'd expect the program below to put only one line with "Eat me" in the log file. However, I get this with Python 2.4.2 in WingIDE on Windows XP: Eat me Ignore me My understanding is: 1. Event "Ignore me" is logged to logger 'spam'. 2. Logger 'spam' has no handler associated with it, so this logger doesn't do anything with the event.
10
2669
by: Baurzhan Ismagulov | last post by:
Hello all, I want that each module has its own logger. I've defined the following config file: keys=f01 keys=console
7
8583
by: flupke | last post by:
Hi, i'm getting errors with the log module concerning RotatingFileHandler. I'm using Python 2.4.3 on Windows XP SP2. This used to work in previous python versions but since i upgraded to 2.4.3 i get these errors: Traceback (most recent call last): File "C:\Python24\lib\logging\handlers.py", line 71, in emit if self.shouldRollover(record):
1
2015
by: Almad | last post by:
Hi, our applications can have plugins as subpackages and I'd like to allow them to use their own logger as well as it's configuration. I thought that best way will be their own configuration file passed to fileConfig. However, I run into problems... 1) It seems that I cannot refer to something from previously loaded
2
2474
by: Robert | last post by:
Hi all I have been trying to set up a framework with logging implemented using the built in Python logging module. For better or worse, I have decided to base the logger names on the module names. This means that I am using multiple layers of name, eg logging.getLogger("a.b.c"). I am also using logging.config to load a file configuration but have been experiencing some unexpected behaviour. If for instance I have something resembling...
3
4299
by: Ross Boylan | last post by:
I would like my different threads to log without stepping on each other. Past advice on this list (that I've found) mostly says to send the messages to a Queue. That would work, but bypasses the logging module's facilities. The logging module itself is "thread-safe", but I think that just means that individual output is protected. If I have, in temporarly sequence:
6
7585
by: Larry Bates | last post by:
Every time I look at the logging module (up until now) I've given up and continue to use my home-grown logger that I've been using for years. I'm not giving up this time ;-) I find that I REALLY need to be able to monitor LOTS of running programs/processes and thought it would be nice to have them use SocketHandler logging and then I would write TCPServer to accept the log messages for real-time monitoring. I Googled (is that now a...
0
8867
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8740
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9386
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9090
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6685
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5996
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3208
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2148
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.