logging breakdown

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marek Augustyn

    logging breakdown

    Hello,

    I'm getting strange exception raised using module logging.
    It's strange because it happens only sometimes, and it happens
    in different places (but always in a logging method).
    i.e. this line of code:

    log.info('SMS sent')

    produces following traceback:

    Traceback (most recent call last):
    File "L:\_progs\pyth on\test\send_sm s.py", line 36, in send_sms
    log.info('SMS sent')
    File "L:\Python23\li b\logging\__ini t__.py", line 893, in info
    apply(self._log , (INFO, msg, args), kwargs)
    File "L:\Python23\li b\logging\__ini t__.py", line 994, in _log
    self.handle(rec ord)
    File "L:\Python23\li b\logging\__ini t__.py", line 1004, in handle
    self.callHandle rs(record)
    File "L:\Python23\li b\logging\__ini t__.py", line 1037, in callHandlers
    hdlr.handle(rec ord)
    File "L:\Python23\li b\logging\__ini t__.py", line 592, in handle
    self.emit(recor d)
    File "L:\Python23\li b\logging\__ini t__.py", line 684, in emit
    self.handleErro r(record)
    File "L:\Python23\li b\logging\__ini t__.py", line 636, in handleError
    traceback.print _exception(ei[0], ei[1], ei[2], None, sys.stderr)
    File "L:\Python23\li b\traceback.py" , line 123, in print_exception
    print_tb(tb, limit, file)
    File "L:\Python23\li b\traceback.py" , line 69, in print_tb
    if line: _print(file, ' ' + line.strip())
    File "L:\Python23\li b\traceback.py" , line 13, in _print
    file.write(str+ terminator)
    IOError: [Errno 9] Bad file descriptor


    This is the way I initialize logging:

    def initLogger(file name):
    log = logging.getLogg er('test')
    formatter = logging.Formatt er('%(asctime)s %(name)s %(levelname)s %(message)s')

    # file
    hdlr = logging.FileHan dler(filename)
    hdlr.setFormatt er(formatter)
    log.addHandler( hdlr)

    # screen
    hdlr = logging.StreamH andler(sys.stdo ut)
    hdlr.setFormatt er(formatter)
    log.addHandler( hdlr)

    log.setLevel(lo gging.DEBUG)

    return log

    log = initLogger('tes t.log')

    I pass variable "log" to functions requesting it.
    My script runs continually, sleeping 1h, doing something, sleeping 1h, etc.
    Is it possible that file handler expires or something?

    Do I do something wrong?

    Thanks,
    Marek Augustyn
Working...