473,396 Members | 1,892 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,396 software developers and data experts.

Why do all my loggers start auto-disabled?

I am a relative newbie to Python and its logging infrastructure;
however, I have programmed extensively with Java/C# and log4j and
log4net. That, I suppose, could be the root of my problem :)

I am trying to setup one logger per module (as this is roughly
analogous to how I've used log4j/log4net). However, I've noticed that
my loggers have the disabled flag set to true (more accurately, 1)
when they are initialized. For each logger, do I have to force
disabled = False? To make this more concrete, here is an example.

In example.py:

import logging
import logging.config

_log = logging.getLogger("prediction.predict")

def main():
logging.config.fileConfig('logconfig.conf')
_log.warn("test warning!")

if __name__ == "__main__":
main()

Unfortunately, this does not print out "test warning!" and if I put a
breakpoint at the _log.warn("test warning!") line, _log.disabled
equals 1. If I change main to:

def main():
logging.config.fileConfig('predict_logconfig.conf' )
_log.disabled = False
_log.warn("test warning!")

It works! So, am I doing something wrong or do I always have to force
my loggers to be enabled? Should I update my configuration file so
that loggers start as enabled? Here is my config file
(logconfig.conf):

[formatters]
keys: detailed,simple

[handlers]
keys: console,filelog

[loggers]
keys: root

[formatter_simple]
format: %(levelname)s : %(module)s.%(funcName)s (%(lineno)d): %
(message)s

[formatter_detailed]
format: %(asctime)s %(levelname)s : %(module)s.%(funcName)s (%
(lineno)d): %(message)s

[handler_console]
class: StreamHandler
args: []
formatter: simple

[handler_filelog]
class: FileHandler
args: ["predictionLog.txt"]
formatter: detailed

[logger_root]
level: INFO
handlers: filelog, console

Aug 25 '08 #1
2 3849
jonfroehlich wrote:
I am a relative newbie to Python and its logging infrastructure;
however, I have programmed extensively with Java/C# and log4j and
log4net. That, I suppose, could be the root of my problem :)

I am trying to setup one logger per module (as this is roughly
analogous to how I've used log4j/log4net). However, I've noticed that
my loggers have the disabled flag set to true (more accurately, 1)
when they are initialized. For each logger, do I have to force
disabled = False? To make this more concrete, here is an example.

In example.py:

import logging
import logging.config

_log = logging.getLogger("prediction.predict")

def main():
logging.config.fileConfig('logconfig.conf')
_log.warn("test warning!")

if __name__ == "__main__":
main()

Unfortunately, this does not print out "test warning!" and if I put a
breakpoint at the _log.warn("test warning!") line, _log.disabled
equals 1. If I change main to:

def main():
logging.config.fileConfig('predict_logconfig.conf' )
_log.disabled = False
_log.warn("test warning!")

It works! So, am I doing something wrong or do I always have to force
my loggers to be enabled? Should I update my configuration file so
that loggers start as enabled? Here is my config file
I think you have to put the logger into your config file to avoid that it
will be disabled by fileConfig():
(logconfig.conf):

[formatters]
keys: detailed,simple

[handlers]
keys: console,filelog
[loggers]
keys: root, predict

# ...

[logger_predict]
qualname: prediction.predict
handlers:

Peter
Aug 25 '08 #2
Calling fileConfig() disables any loggers existing at the time of the
call. Make sure you call fileConfig() before instantiating any
loggers; after that you can instantiate as many as you like, and they
will all be enabled. Make sure you don't call fileConfig() again, as
in that call all loggers which are not named in the configuration will
be disabled.

The reason why fileConfig() disables existing loggers is that it was
designed as a one-off configuration (which completely replaces any
existing configuration with that specified in the config file) - not
as an incremental configurator.

Best regards,

Vinay Sajip
Aug 26 '08 #3

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

Similar topics

16
by: Kerry Neilson | last post by:
For the past couple of months, Idle won't start when I invoke it. I am at a complete loss for why this is. When this happens, they python command line still starts, and python works fine...
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...
2
by: Frank Py | last post by:
I have a SQL Server 2000 that failed to start after a Windows reboot. Agent properties are checked to auto start if stopped. Under the Agent Error Log, I have the following data: Information:...
1
by: Gill Bates | last post by:
Can you help ? <!doctype html public "-//W3C//DTD HTML 4.01 Frameset//EN"> <html> <head> <title>set</title> <script type="text/ecmascript"> var tid; function syncFrame (){ boven.scrollTo...
16
by: John Baker | last post by:
Hi: I know this is a strange question, but I have inherited a system where files are copied and records re auto numbered (as an index field) )frequently, and I am wondering how high the number...
19
by: Oliver Neumann | last post by:
Hello, im new to c# and i got an app with a notifyicon. Now i want to start the app only with the notifyIcon, so that the Main-Form doesnt show up. The form itself is used at the entrance...
3
by: bwalke | last post by:
I was wondering how the Process.Start() command can be used in a VB.NET Web Application. I have used this command in a Windows Application before successfully. I want the client side to envoke the...
10
by: Stephany Young | last post by:
When one uses the System.Diagnostics.Process.Start method to launch a common or garden Console application, one can set the WindowStyle property of the StartInfo object to ProcessWindowStyle.Hidden...
1
by: belred | last post by:
is there a way to dynamically get all the active loggers? i currently have code like this in different areas of the program: import logging log = logging.getLogger('foo') i would like to...
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
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...

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.