Specifying two log files with one configuration file

Discussion in 'Python' started by Peter Steele, Jan 6, 2013.

  1. Peter Steele

    Peter Steele Guest

    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?
     
    Peter Steele, Jan 6, 2013
    #1
    1. Advertising

  2. Peter Steele

    Vinay Sajip Guest

    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
     
    Vinay Sajip, Jan 9, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. valentin tihomirov

    Specifying generics in configuration

    valentin tihomirov, Jan 5, 2004, in forum: VHDL
    Replies:
    14
    Views:
    1,014
    valentin tihomirov
    Jan 7, 2004
  2. GenxLogic
    Replies:
    3
    Views:
    1,370
    andrewmcdonagh
    Dec 6, 2006
  3. valentin tihomirov
    Replies:
    0
    Views:
    295
    valentin tihomirov
    Sep 14, 2007
  4. Replies:
    3
    Views:
    362
    Vinay Sajip
    Apr 23, 2008
  5. Replies:
    2
    Views:
    252
    Vinay Sajip
    Sep 16, 2012
Loading...

Share This Page