logging module question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • s99999999s2003@yahoo.com

    logging module question

    hi
    i have defined a function
    def logger(logfile, msg):
    import logging

    logging.basicCo nfig(level=logg ing.DEBUG,
    format='%(ascti me)s %(levelname)-8s
    %(message)s',
    datefmt='%a, %d %b %Y %H:%M:%S',
    filename='%s' % (logfile),
    filemode='a')
    logging.critica l(msg)
    logging.error(m sg)
    logging.warning (msg)
    logging.info(ms g)
    logging.shutdow n()

    In my main code:

    ----- some python code here---
    logger("test.lo g","error")
    ......
    ......
    logger("test.lo g","another error")
    ....
    logger("test.lo g","yet another error")
    ....
    sys.exit(0)

    When i do the above, i get :
    self.stream.wri te(fs % msg)
    ValueError: I/O operation on closed file

    If i removed logging.shutdow n(), it workds..what is wrong with my
    function ?
    thanks

  • Martin Jürgens

    #2
    Re: logging module question

    Am Thu, 29 Jun 2006 20:22:28 -0700 schrieb s99999999s2003:
    [color=blue]
    > hi
    > i have defined a function
    > def logger(logfile, msg):
    > import logging
    >
    > logging.basicCo nfig(level=logg ing.DEBUG,
    > format='%(ascti me)s %(levelname)-8s
    > %(message)s',
    > datefmt='%a, %d %b %Y %H:%M:%S',
    > filename='%s' % (logfile),
    > filemode='a')
    > logging.critica l(msg)
    > logging.error(m sg)
    > logging.warning (msg)
    > logging.info(ms g)[/color]

    Why log the same message with different severity ?
    [color=blue]
    > logging.shutdow n()
    >
    > In my main code:
    >
    > ----- some python code here---
    > logger("test.lo g","error")
    > .....
    > .....
    > logger("test.lo g","another error")
    > ...
    > logger("test.lo g","yet another error")
    > ...
    > sys.exit(0)
    >
    > When i do the above, i get :
    > self.stream.wri te(fs % msg)
    > ValueError: I/O operation on closed file
    >
    > If i removed logging.shutdow n(), it workds..what is wrong with my
    > function ?
    > thanks[/color]

    Why exactly do you call logging.shutdow n() when you use the logging system
    again with further calls to logger().

    As far as I see it logging.shutdow n() should only be called when you're
    done with logging alltogether. However in your case you probably don't
    need to call it at all since it's invoked automatically when yout program
    exits.

    Regards,

    Martin

    Comment

    Working...