logging module question

Discussion in 'Python' started by s99999999s2003@yahoo.com, Jun 30, 2006.

  1. Guest

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

    logging.basicConfig(level=logging.DEBUG,
    format='%(asctime)s %(levelname)-8s
    %(message)s',
    datefmt='%a, %d %b %Y %H:%M:%S',
    filename='%s' % (logfile),
    filemode='a')
    logging.critical(msg)
    logging.error(msg)
    logging.warning(msg)
    logging.info(msg)
    logging.shutdown()

    In my main code:

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

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

    If i removed logging.shutdown(), it workds..what is wrong with my
    function ?
    thanks
     
    , Jun 30, 2006
    #1
    1. Advertising

  2. Am Thu, 29 Jun 2006 20:22:28 -0700 schrieb s99999999s2003:

    > hi
    > i have defined a function
    > def logger(logfile,msg):
    > import logging
    >
    > logging.basicConfig(level=logging.DEBUG,
    > format='%(asctime)s %(levelname)-8s
    > %(message)s',
    > datefmt='%a, %d %b %Y %H:%M:%S',
    > filename='%s' % (logfile),
    > filemode='a')
    > logging.critical(msg)
    > logging.error(msg)
    > logging.warning(msg)
    > logging.info(msg)


    Why log the same message with different severity ?

    > logging.shutdown()
    >
    > In my main code:
    >
    > ----- some python code here---
    > logger("test.log","error")
    > .....
    > .....
    > logger("test.log","another error")
    > ...
    > logger("test.log","yet another error")
    > ...
    > sys.exit(0)
    >
    > When i do the above, i get :
    > self.stream.write(fs % msg)
    > ValueError: I/O operation on closed file
    >
    > If i removed logging.shutdown(), it workds..what is wrong with my
    > function ?
    > thanks


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

    As far as I see it logging.shutdown() 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
     
    =?iso-8859-1?q?Martin_J=FCrgens?=, Jun 30, 2006
    #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. Stefan Siegl
    Replies:
    0
    Views:
    963
    Stefan Siegl
    Aug 27, 2003
  2. janne
    Replies:
    0
    Views:
    9,509
    janne
    Sep 10, 2004
  3. rh0dium
    Replies:
    2
    Views:
    345
    rh0dium
    Aug 4, 2005
  4. Christoph Haas
    Replies:
    0
    Views:
    457
    Christoph Haas
    Jun 12, 2006
  5. Christoph Haas
    Replies:
    1
    Views:
    462
    Vinay Sajip
    Jun 14, 2006
Loading...

Share This Page