logging breakdown

M

Marek Augustyn

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\python\test\send_sms.py", line 36, in send_sms
log.info('SMS sent')
File "L:\Python23\lib\logging\__init__.py", line 893, in info
apply(self._log, (INFO, msg, args), kwargs)
File "L:\Python23\lib\logging\__init__.py", line 994, in _log
self.handle(record)
File "L:\Python23\lib\logging\__init__.py", line 1004, in handle
self.callHandlers(record)
File "L:\Python23\lib\logging\__init__.py", line 1037, in callHandlers
hdlr.handle(record)
File "L:\Python23\lib\logging\__init__.py", line 592, in handle
self.emit(record)
File "L:\Python23\lib\logging\__init__.py", line 684, in emit
self.handleError(record)
File "L:\Python23\lib\logging\__init__.py", line 636, in handleError
traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)
File "L:\Python23\lib\traceback.py", line 123, in print_exception
print_tb(tb, limit, file)
File "L:\Python23\lib\traceback.py", line 69, in print_tb
if line: _print(file, ' ' + line.strip())
File "L:\Python23\lib\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(filename):
log = logging.getLogger('test')
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')

# file
hdlr = logging.FileHandler(filename)
hdlr.setFormatter(formatter)
log.addHandler(hdlr)

# screen
hdlr = logging.StreamHandler(sys.stdout)
hdlr.setFormatter(formatter)
log.addHandler(hdlr)

log.setLevel(logging.DEBUG)

return log

log = initLogger('test.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top