Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Specifying two log files with one configuration file

Reply
Thread Tools

Specifying two log files with one configuration file

 
 
Peter Steele
Guest
Posts: n/a
 
      01-06-2013
I want to configure the Python logging module to manage two separate log files, allowing me to do something like this:

import logging
import logging.config
logging.config.fileConfig("mylogging.conf")
root = logging.getLogger()
test = logging.getLogger("test")

root.debug("This is a message targeted to the root log file")
test.debug("This is a message targeted to the test log file")

I have been unable to get this to work. My current conf file looks like this:

[formatters]
keys: simple

[handlers]
keys: root,test

[loggers]
keys: root,test

[formatter_simple]
format=%(asctime)s - %(levelname)s - %(message)s

[handler_root]
class: handlers.RotatingFileHandler
args: ('/var/log/root.log', 'a', 1024000, 14)
formatter: simple

[handler_test]
class: handlers.RotatingFileHandler
args: ('/var/log/test.log', 'a', 1024000, 14)
formatter: simple

[logger_root]
level: DEBUG
handlers: root
qualname:

[logger_test]
level: DEBUG
handlers: test
qualname:

With this setup, all of my log messages go to test.log. root.log is created, but nothing gets logged to it. What do I need in my logging conf file to have two separate log file destinations?
 
Reply With Quote
 
 
 
 
Vinay Sajip
Guest
Posts: n/a
 
      01-09-2013
Peter Steele <pwsteele <at> gmail.com> writes:

> I have been unable to get this to work. My current conf file looks like this:


Try with the following changes:

[logger_test]
level: DEBUG
handlers: test
propagate: 0
qualname: test

The qualname: test is what identifies the logger as the logger named 'test', and
propagate: 0 prevents the test message from being passed up to the root logger.

Regards,

Vinay Sajip

 
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
Python Logging: Specifying converter attribute of a log formatter inconfig file srimanthula.radhakrishna@gmail.com Python 2 09-16-2012 08:07 AM
Choosing log file destination in logging configuration file guybenron@gmail.com Python 3 04-23-2008 04:50 PM
Specifying an empty asp.net configuration application setting value valentin tihomirov ASP .Net 0 09-14-2007 08:32 AM
How to compare two SOAP Envelope or two Document or two XML files GenxLogic Java 3 12-06-2006 08:41 PM
Specifying generics in configuration valentin tihomirov VHDL 14 01-07-2004 05:27 PM



Advertisments