Hello all,
I want that each module has its own logger. I've defined the following
config file:
[formatters]
keys=f01
[handlers]
keys=console
[loggers]
keys=root,l01
[formatter_f01]
format=%(name)s : %(message)s
[handler_console]
class=StreamHan dler
args=[]
formatter=f01
[logger_root]
level=CRITICAL
handlers=consol e
[logger_l01]
level=DEBUG
qualname=l01
handlers=consol e
I use it like this:
import logging
import logging.config
logging.config. fileConfig('a.c onf')
log = logging.getLogg er('l01')
log.debug('zzz' )
I want logger_root to go to /dev/null, so I've configured it with level
CRITICAL. My understanding is that in this way debug messages are not
printed on logger_root's handler. However, running the program results
in the message being printed twice. What is the problem?
Thanks in advance,
Baurzhan. 10 2650
Baurzhan Ismagulov wrote: Hello all,
I want that each module has its own logger. I've defined the following config file:
[logger_root] level=CRITICAL handlers=consol e
[logger_l01] level=DEBUG qualname=l01 handlers=consol e
I want logger_root to go to /dev/null, so I've configured it with level CRITICAL. My understanding is that in this way debug messages are not printed on logger_root's handler. However, running the program results in the message being printed twice. What is the problem?
You've defined the handler against both the root logger and l01. You
only need it configured for the root logger - events passed to l01 will
be passed to all handlers up the hierarchy. So remove the
"handlers=conso le" line from [logger_l01] and it should print the
message just once.
Vinay Sajip
Hello Vinay,
On Tue, May 23, 2006 at 04:13:38PM -0700, Vinay Sajip wrote: [logger_root] level=CRITICAL handlers=consol e
[logger_l01] level=DEBUG qualname=l01 handlers=consol e
I want logger_root to go to /dev/null, so I've configured it with level CRITICAL. My understanding is that in this way debug messages are not printed on logger_root's handler. However, running the program results in the message being printed twice. What is the problem?
You've defined the handler against both the root logger and l01. You only need it configured for the root logger - events passed to l01 will be passed to all handlers up the hierarchy. So remove the "handlers=conso le" line from [logger_l01] and it should print the message just once.
Thanks for the idea! I think this should work for the example I sent.
However, I have more than one module, and I want to log only l01. How
can I do that?
Thanks in advance,
Baurzhan.
Baurzhan Ismagulov wrote: Thanks for the idea! I think this should work for the example I sent. However, I have more than one module, and I want to log only l01. How can I do that?
I don't know what your logger hierarchy looks like: you could perhaps
log to child loggers of l01 ("l01.XXX"), or set all other loggers you
use to have a CRITICAL level, or filter them using a filter which
filters out everything.
Regards,
Vinay
Hello Vinay,
On Thu, May 25, 2006 at 10:14:00AM -0700, Vinay Sajip wrote: I don't know what your logger hierarchy looks like: you could perhaps log to child loggers of l01 ("l01.XXX"), or set all other loggers you use to have a CRITICAL level, or filter them using a filter which filters out everything.
Ok, here is my hierarchy:
[formatters]
keys=f01
[handlers]
keys=console
[loggers]
keys=root,l01,l 02
[formatter_f01]
format=%(name)s : %(message)s
[handler_console]
class=StreamHan dler
args=[]
formatter=f01
[logger_root]
level=CRITICAL
handlers=consol e
[logger_l01]
level=DEBUG
qualname=l01
handlers=consol e
[logger_l02]
level=CRITICAL
qualname=l02
handlers=consol e
The program is:
import logging
import logging.config
logging.config. fileConfig('a.c onf')
log1 = logging.getLogg er('l01')
log2 = logging.getLogg er('l02')
log1.debug('zzz ')
log2.debug('qqq ')
With the config above, I expect that zzz gets printed, and qqq doesn't.
When I run the script, zzz is printed twice, and qqq isn't. I want that
zzz is printed once. How do I do that? I can add a filter if this can't
be done otherwise, however, I'm at the moment reluctant to do that since
I don't see why CRITICAL for root passes zzz through and drops qqq
correctly for l02.
Thanks in advance,
Baurzhan.
Baurzhan Ismagulov wrote: Hello Vinay, Ok, here is my hierarchy:
[snip] [handlers] keys=console
[snip] [logger_root] level=CRITICAL handlers=consol e
[logger_l01] level=DEBUG qualname=l01 handlers=consol e
[logger_l02] level=CRITICAL qualname=l02 handlers=consol e
[snip]
With the config above, I expect that zzz gets printed, and qqq doesn't. When I run the script, zzz is printed twice, and qqq isn't. I want that zzz is printed once. How do I do that? I can add a filter if this can't be done otherwise, however, I'm at the moment reluctant to do that since I don't see why CRITICAL for root passes zzz through and drops qqq correctly for l02.
Did you try removing the handler from l01, as I suggested in an earlier
reply? The config above still has the console handler attached to root,
l01 and l02. The reason that zzz is printed twice is that when a logger
decides to process an event, it is passed to handlers attached to
ancestor loggers (unless propagate is set to 0 - but this is not the
normal situation). So, log1 is deciding to process the event (based on
the level), and passing it to its own handlers (l01->console) and then
to its ancestor loggers' handlers (root->console). Remove the handlers
from l01 and l02 and try again.
Hello Vinay,
On Tue, May 30, 2006 at 09:13:25AM -0700, Vinay Sajip wrote: [snip] [handlers] keys=console [snip] [logger_root] level=CRITICAL handlers=consol e
[logger_l01] level=DEBUG qualname=l01 handlers=consol e
[logger_l02] level=CRITICAL qualname=l02 handlers=consol e [snip]
.... When I run the script, zzz is printed twice, and qqq isn't. I want that zzz is printed once.
.... Did you try removing the handler from l01, as I suggested in an earlier reply?
I had removed the whole line, and it complained about the missing
handlers line. Now I've tried with 'handlers=', this seems to work.
Thanks much!
The reason that zzz is printed twice is that when a logger decides to process an event, it is passed to handlers attached to ancestor loggers (unless propagate is set to 0 - but this is not the normal situation). So, log1 is deciding to process the event (based on the level), and passing it to its own handlers (l01->console) and then to its ancestor loggers' handlers (root->console).
Hmm, log1 decides once whether to print an event, and after that it gets
printed in log1 and all its ancestors, regardless of their level? I find
this quite counter-intuitive. I'd instead expect that each logger
decides whether to print an event according to its own level. Could you
give an example why one would want the python behavior?
With kind regards,
Baurzhan. ib*@radix50.net wrote: Hello Vinay,
Hmm, log1 decides once whether to print an event, and after that it gets printed in log1 and all its ancestors, regardless of their level? I find this quite counter-intuitive. I'd instead expect that each logger decides whether to print an event according to its own level. Could you give an example why one would want the python behavior?
Loggers are hierarchical for a reason - not just randomly named
channels. Just as it is generally useful to develop a system by
modularising it into subsystems, packages, modules, etc. so it is
useful when logging to follow a parallel hierarchy. The audiences for
the logging events are orthogonal to the events themselves, and the way
the logging module is organised reflects good practice as determined by
practical experience over a period of time. The approach you're
questioning is not specific to Python - log4j (which inspired Python's
logging), and the logging built into Java 1.4, also work this way.
Practically, this makes configuration a lot simpler; if I want to log
everything to console, I just attach a handler to the root logger, and
I never have to worry about attaching to every single logger. (Logger
names are generally not cast in stone - I might break down a module's
logic into smaller pieces and thus introduce new logger names to
describe events in the refactored module. I certainly don't want to
change my logging configuration every time I refactor my code.)
May I suggest you review the log4j documentation to get a better
exposition of the principles which govern the design of such logging
systems.
Hello Vinay,
On Wed, May 31, 2006 at 03:05:13PM -0700, Vinay Sajip wrote: Hmm, log1 decides once whether to print an event, and after that it gets printed in log1 and all its ancestors, regardless of their level? I find this quite counter-intuitive. I'd instead expect that each logger decides whether to print an event according to its own level. Could you give an example why one would want the python behavior?
Loggers are hierarchical for a reason - not just randomly named channels. ...
Thanks for the explanation! Please note that I am not questioning the
usefulness of hierarchical logging -- I think it's a Good Thing. What I
can't understand is the motivation for the single place of decision
whether a message should be printed ("is enabled" in log4j terms) or
not.
Consider the following scenario: root is CRITICAL, l01 is DEBUG, a debug
message is logged on l01. l01 decides that the message should be
printed, and _both_ root and l01 print it. Now, it is good that the
message is propagated to root, but why doesn't root decide for itself
whether to print it or not?
For instance, I log root to syslog and have only critical messages
there. I log l01 to console to debug. I want that my message to l01 is
not printed by root since its level is CRITICAL. This is why I want that
each logger re-evaluates the message level for itself. Could you perhaps
give a useful example why one could want loggers to decide once?
And another thing I couldn't find how to do: I want to have several
debug levels. I can log messages without problems, but numeric values in
the configuration file cause error messages during
logging.config. fileConfig. Can I specify numeric values in the config
file?
With kind regards,
Baurzhan.
Hello Baurzhan, Consider the following scenario: root is CRITICAL, l01 is DEBUG, a debug message is logged on l01. l01 decides that the message should be printed, and _both_ root and l01 print it. Now, it is good that the message is propagated to root, but why doesn't root decide for itself whether to print it or not?
It's not propagated to the root logger (or to ancestor loggers in
general) - just to the handlers associated with ancestor loggers.
For instance, I log root to syslog and have only critical messages there. I log l01 to console to debug. I want that my message to l01 is not printed by root since its level is CRITICAL. This is why I want that each logger re-evaluates the message level for itself. Could you perhaps give a useful example why one could want loggers to decide once?
You can set levels on handlers as well as loggers. So if you add a
syslog handler to the root and set its level to CRITICAL, only CRITICAL
messages are sent to syslog.
And another thing I couldn't find how to do: I want to have several debug levels. I can log messages without problems, but numeric values in the configuration file cause error messages during logging.config. fileConfig. Can I specify numeric values in the config file?
You should use addLevelName to add custom levels. You can do e.g.
logging.MYCUSTO MLEVEL = 25
logging.addLeve lName(logging.M YCUSTOMLEVEL, "MYCUSTOMLEVEL" )
and then reference MYCUSTOMLEVEL in the config file.
Regards,
Vinay This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jjesso |
last post by:
I am trying to add a new logging level.
logging.config.fileConfig("bengineLog.cfg")
logging.CLIENT = logging.INFO + 1
logging.addLevelName( logging.CLIENT, 'CLIENT' )
logging.root.setLevel( )
logger = logging.getLogger(None)
logging.Logger.client('test')
I get error:
|
by: Karuppasamy |
last post by:
H
I am trying to use the Logging Module provided by Microsoft Application Blocks for .Net
I installed everything as per the Instructions given in the 'Development Using the Logging Block'
But when i am trying to run the sample, i am getting the following error in the Event Viwer
Kindly help me on this
|
by: pmatos |
last post by:
Hi all,
I am trying to create a simple but efficient C++ logging class. I know
there are lots of them out there but I want something simple and
efficient. The number one requirement is the possibility of shutting
logging down at compile time and suffer no performance penalty
whatsoever for getting logging on whenever I wish. Of course that...
|
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 %(function)s, which results in
the name
of the entity which logged the record. My version even deduces the
class name in the case which the logger...
|
by: Burkhard Schultheis |
last post by:
As I wrote last week, we have a problem with a DB2 V8 on Linux. Here is
what is in db2diag.log during online backup:
Starting a full database backup.
2004-04-01-02.33.54.760164 Instance:lzgneu Node:000
PID:1293(db2loggw (TELEMATX)) TID:1024 Appid:none
data protection sqlpgwlp Probe:909
TailPage 0 does not match pagelsn...
| |
by: robert |
last post by:
As more and more python packages are starting to use the bloomy
(Java-ish) 'logging' module in a mood of responsibility and as I am not
overly happy with the current "thickener" style of usage, I want to put
this comment and a alternative most simple default framework for
discussion.
Maybe there are more Python users which like to see that...
|
by: rajesh.hanchate |
last post by:
Please help me in resolving this issue.
I am using EnterpriseLibrary 2.0 Exception and logging block for
logging exceptions to event log. It works fine for sometime. After some
time it stops logging to event log. To make it active again I need to
open the web.config and save without making any changes. It starts to
work again.
Here is the...
|
by: Chris Shenton |
last post by:
I am setting up handlers to log DEBUG and above to a rotating file and
ERROR and above to console. But if any of my code calls a logger
(e.g., logging.error("foo")) before I setup my handlers, the logging
system will create a default logger that *also* emits logs, which I
can't seem to get rid of. Is there a way I can suppress the creation...
|
by: Lowell Alleman |
last post by:
Here is the situation: I wrote my own log handler class (derived from
logging.Handler) and I want to be able to use it from a logging config
file, that is, a config file loaded with the
logging.config.fileConfig() function.
Let say my logging class is called "MyLogHandler" and it's in a module
called "mylogmodule", I want to be able to...
|
by: samwyse |
last post by:
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...
|
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...
| |
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...
|
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. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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...
| |
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...
|
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
| |