473,479 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

NTEventLogHandler not logging `info'?

This code doesn't seem to do what I think it should do:

# python 2.3.2
# not sure of my win32 extensions version

import logging
from logging.handlers import NTEventLogHandler
logger = logging.getLogger("testlogger")
handler = NTEventLogHandler("testlogger")
logger.addHandler(handler)
logger.info("This is a test")
I expected to see an `information' message in my `Application' event
log. Any ideas?

Thanks,
jw
Sep 22 '05 #1
5 2447
Jaime Wyant wrote:
This code doesn't seem to do what I think it should do:

# python 2.3.2
# not sure of my win32 extensions version

import logging
from logging.handlers import NTEventLogHandler
logger = logging.getLogger("testlogger")
handler = NTEventLogHandler("testlogger")
logger.addHandler(handler)
logger.info("This is a test")
I expected to see an `information' message in my `Application' event
log. Any ideas?


By default, the logger's level is WARNING, because you haven't
explicitly set a level and the level inherited from the parent logger
is WARNING (this is the default value for the root logger level). So if
you add a line before the logger.info() call:

logger.setLevel(logging.INFO) # or you can use logging.DEBUG

Then you should see an entry appear in the NT Event log.

Sep 22 '05 #2
I must be missing something. This is what I read from the documentation:

When a logger is created, the level is set to NOTSET (which causes all
messages to be processed in the root logger, or delegation to the
parent in non-root loggers).

:/

Thanks!
jw

On 22 Sep 2005 08:21:48 -0700, Vinay Sajip <vi*********@yahoo.co.uk> wrote:
Jaime Wyant wrote:
This code doesn't seem to do what I think it should do:

# python 2.3.2
# not sure of my win32 extensions version

import logging
from logging.handlers import NTEventLogHandler
logger = logging.getLogger("testlogger")
handler = NTEventLogHandler("testlogger")
logger.addHandler(handler)
logger.info("This is a test")
I expected to see an `information' message in my `Application' event
log. Any ideas?


By default, the logger's level is WARNING, because you haven't
explicitly set a level and the level inherited from the parent logger
is WARNING (this is the default value for the root logger level). So if
you add a line before the logger.info() call:

logger.setLevel(logging.INFO) # or you can use logging.DEBUG

Then you should see an entry appear in the NT Event log.

--
http://mail.python.org/mailman/listinfo/python-list

Sep 22 '05 #3
BTW - you're suggestion worked.

Thanks again!
jw

On 9/22/05, Jaime Wyant <pr***********@gmail.com> wrote:
I must be missing something. This is what I read from the documentation:

When a logger is created, the level is set to NOTSET (which causes all
messages to be processed in the root logger, or delegation to the
parent in non-root loggers).

:/

Thanks!
jw

On 22 Sep 2005 08:21:48 -0700, Vinay Sajip <vi*********@yahoo.co.uk> wrote:
Jaime Wyant wrote:
This code doesn't seem to do what I think it should do:

# python 2.3.2
# not sure of my win32 extensions version

import logging
from logging.handlers import NTEventLogHandler
logger = logging.getLogger("testlogger")
handler = NTEventLogHandler("testlogger")
logger.addHandler(handler)
logger.info("This is a test")
I expected to see an `information' message in my `Application' event
log. Any ideas?


By default, the logger's level is WARNING, because you haven't
explicitly set a level and the level inherited from the parent logger
is WARNING (this is the default value for the root logger level). So if
you add a line before the logger.info() call:

logger.setLevel(logging.INFO) # or you can use logging.DEBUG

Then you should see an entry appear in the NT Event log.

--
http://mail.python.org/mailman/listinfo/python-list

Sep 22 '05 #4
Jaime Wyant wrote:
I must be missing something. This is what I read from the documentation:

When a logger is created, the level is set to NOTSET (which causes all
messages to be processed in the root logger, or delegation to the
parent in non-root loggers).


The documentation could be clearer, I agree. I will add the following
clarifying sentence to the docs:

The term "delegation to the parent" means that if a logger has a level
of NOTSET, its ancestor loggers are examined until the root is reached,
or an ancestor with a level other than NOTSET is found. In the latter
case, that level is treated as the effective level of the logger where
the ancestor search started, and is used to determine how a logging
event is handled. If the root is reached, and it has a level of NOTSET,
then all messages will be processed. Otherwise, the root's level will
be used as the effective level.

Please post a response on the list if you think the above is still not
clear enough.

Sep 22 '05 #5
On 22 Sep 2005 12:23:50 -0700, Vinay Sajip <vi*********@yahoo.co.uk> wrote:
Jaime Wyant wrote:
I must be missing something. This is what I read from the documentation:

When a logger is created, the level is set to NOTSET (which causes all
messages to be processed in the root logger, or delegation to the
parent in non-root loggers).


Thanks for your attentiveness!
The documentation could be clearer, I agree. I will add the following
clarifying sentence to the docs:

The term "delegation to the parent" means that if a logger has a level
of NOTSET, its ancestor loggers are examined until the root is reached,
or an ancestor with a level other than NOTSET is found. In the latter
case, that level is treated as the effective level of the logger where
the ancestor search started, and is used to determine how a logging
event is handled. If the root is reached, and it has a level of NOTSET,
then all messages will be processed. Otherwise, the root's level will
be used as the effective level.

Please post a response on the list if you think the above is still not
clear enough.


After re-reading the documentation I posted originally, it makes much
more sense and I feel much more stupid *smacks self in head*. Your
definition of "delegation of the parent" is right on the mark, however
I found myself having to read it a few times to have it `sink in'.

I've rewritten it below in a bit easier to read fashion (I think).

The term "delegation to the parent" means that if a logger has a level
of NOTSET, its chain of ancestor loggers are traversed until an
ancestor with a level other than NOTSET is found or the root is
reached.

If an ancestor is found with a level other than NOTSET, then that
ancestor's level is treated as the effective level of the logger where
the ancestor search began, and is used to determine how a logging
event is handled.

If the root is reached, and it has a level of NOTSET, then all
messages will be processed. Otherwise, the root's level will be used
as the effective level.

HTH,
jw
Sep 22 '05 #6

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

Similar topics

0
1302
by: Marek Augustyn | last post by:
Hello, I'm getting strange exception raised using module logging. It's strange because it happens only sometimes, and it happens in different places (but always in a logging method). i.e. this...
6
10859
by: Ville Vainio | last post by:
Just posting this for the sake of google: Like everyone else, I figured it's time to start using the 'logging' module. I typically want to dump "info" level (and up) log information to...
0
1665
by: Neil Benn | last post by:
Hello, I'm running a test and having issues with logging, if I call logging.shutdown() and then want to start the logging going again then I get a problem as if I call shutdown, I can't get the...
1
3647
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( )...
3
1431
by: olsongt | last post by:
I'm trying to be a good boy and use the logging module but it's behaving rather counter-intuitively. I've posted a simplified test script below. To summarize, I've set the basic config to only...
23
2180
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...
7
2409
by: Jed Parsons | last post by:
Hi, I'm using the logging module for the first time. I'm using it from within Zope Extensions. My problem is that, for every event logged, the logger is producing multiple identical entries...
3
1594
by: seb | last post by:
Hi, I am writing to a file some basic information using the logging module. It is working but in the log file some line are printed several time. I had put some print debugging messages in the...
12
1903
by: Eric S. Johansson | last post by:
I need to to be able to conditionally log based on the method the log statement is in and one other factor like a log level. in order to do so, I need to be able to automatically find out the name...
0
7027
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
7019
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
7067
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
6719
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
6847
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...
1
4757
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
4463
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
2980
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...
1
555
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.