python logging writes an empty file

Discussion in 'Python' started by Ovidiu Deac, Mar 26, 2010.

  1. Ovidiu Deac

    Ovidiu Deac Guest

    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
    Ovidiu Deac, Mar 26, 2010
    #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. Stefan Siegl
    Replies:
    0
    Views:
    953
    Stefan Siegl
    Aug 27, 2003
  2. Christoph Haas
    Replies:
    0
    Views:
    444
    Christoph Haas
    Jun 12, 2006
  3. Christoph Haas
    Replies:
    1
    Views:
    450
    Vinay Sajip
    Jun 14, 2006
  4. Royan
    Replies:
    1
    Views:
    1,445
    Andrea Francia
    Apr 1, 2008
  5. Ovidiu Deac

    Re: python logging writes an empty file

    Ovidiu Deac, Mar 26, 2010, in forum: Python
    Replies:
    2
    Views:
    998
    Ovidiu Deac
    Mar 26, 2010
Loading...

Share This Page