Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > python logging writes an empty file

Reply
Thread Tools

python logging writes an empty file

 
 
Ovidiu Deac
Guest
Posts: n/a
 
      03-26-2010
Hi,

I have the following situation:

My application uses nosetests to discover&run the unittests. I pass
the log configuration file as --logging-config=logging.conf
Everything works just fine, the logs are printed as required by the
configuration file which makes me happy. I take this as a sign that my
logging.conf is correct

Then in my main script, which starts the production application, I
have this line:
logging.config.fileConfig("logging.conf")

The logging module is configured without errors BUT my output.log is
EMPTY. It's like all the messages are filtered.

If I configure logging like this:
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(name)-12s %(levelname)s: %(message)s',
datefmt='%m-%d %H:%M:%S',
filename=file,
filemode='w')
Then the logs are printed ok.

Then I tried this:
file = logging.FileHandler(logFileBasename, 'w')
file.setLevel(logging.INFO)
# set a format which is simpler for console use
formatter = logging.Formatter('%(asctime)s %(name)-12s
%(levelname)-8s %(message)s',)
# tell the handler to use this format
file.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(file)
logging.getLogger('')

....which also leaves my output file EMPTY.

I'm out of ideas. Can anybody help me with this?

Thanks in advance!
ovidiu

Here is my logging.conf:

[formatters]
keys: detailed,simple

[handlers]
keys: console,file

[loggers]
keys: root

[formatter_simple]
format: %(name)s:%(levelname)s: %(message)s

[formatter_detailed]
format: %(name)s:%(levelname)s %(module)s:%(lineno)d: %(message)s

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

[handler_file]
class=FileHandler
level=DEBUG
formatter=detailed
args=('output.log', 'w')
filename=output.log
mode=w

[logger_root]
level: INFO
handlers: file
propagate: 1
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: python logging writes an empty file Ovidiu Deac Python 2 03-26-2010 08:08 PM
How python writes text into another windows application Meitham Python 3 11-01-2007 09:15 PM
Synchronous writes to a file Erick Sasse ASP .Net 10 10-07-2005 10:59 PM
Design Question: Managing multiple writes to flat file Rhino Java 4 03-24-2005 08:54 PM
download writes html code to file =?Utf-8?B?QUNhdW50ZXI=?= ASP .Net 3 01-11-2005 07:29 PM



Advertisments