Specifying two log files with one configuration file

Peter Steele pwsteele at gmail.com
Sun Jan 6 14:10:45 EST 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?



More information about the Python-list mailing list