logging with logging.config.fileConfig

Discussion in 'Python' started by Herman, Feb 19, 2012.

  1. Herman

    Herman Guest

    I tried to use file to config my logger and I got a weird situation
    that each message is outputted twice...
    Here is my scenario:
    python: 2.6

    file abc_logging.conf:

    [loggers]
    keys=root,abc

    [handlers]
    keys=consoleHandler

    [formatters]
    keys=detailFormatter

    [logger_root]
    level=DEBUG
    handlers=consoleHandler

    [logger_abc]
    level=DEBUG
    handlers=consoleHandler
    qualname=abc

    [handler_consoleHandler]
    class=StreamHandler
    level=DEBUG
    formatter=detailFormatter
    args=(sys.stdout,)

    [formatter_detailFormatter]
    format=%(asctime)-15s %(levelname)s: %(filename)s:%(lineno)s: %(message)s
    datefmt=%Y-%m-%d %H:%M:%S


    Then in my program, i config the file with this:

    SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
    logging.config.fileConfig(SCRIPT_DIR + os.path.sep + 'abc_logging.conf')
    LOG = logging.getLogger('abc')


    I tried to print out the logger handlers with this:
    print("*"*10)
    print("number of handlers: %s" % len(LOG.handlers))
    print(LOG.handlers)
    LOG.debug(sql)

    But there is no suspicious behavior:

    **********
    number of handlers: 1
    [<logging.StreamHandler instance at 0xf23518>]
    2012-02-19 12:21:56 DEBUG: abc.py:88: SELECT ...
    2012-02-19 12:21:56 DEBUG: abc.py:88: SELECT ...
    Herman, Feb 19, 2012
    #1
    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. Almad
    Replies:
    1
    Views:
    310
    Vinay Sajip
    Oct 7, 2006
  2. Robert
    Replies:
    0
    Views:
    424
    Robert
    Aug 30, 2007
  3. Lowell Alleman
    Replies:
    3
    Views:
    533
    Vinay Sajip
    May 29, 2008
  4. Alexandru  Moșoi

    how to use logging.config.fileConfig ?

    Alexandru Moșoi, Apr 10, 2009, in forum: Python
    Replies:
    1
    Views:
    687
    Vinay Sajip
    Apr 11, 2009
  5. Jeffrey Britton
    Replies:
    3
    Views:
    530
    Jeffrey Britton
    Apr 18, 2012
Loading...

Share This Page