I have a logger that functions properly at the start of a script, then breaks in the middle. It looks like its handler is getting overwritten by a str, but I can't figure out where.
At the start of the script, I'm printing the handler and its level. The following code:
print 'Array of handlers', logger.handlers
for h in logger.handlers:
print 'Handler', h
print 'Handler level', h.level
produces this:
Array of handlers [<logging.FileHandler instance at 0x19ef320>]
Handler <logging.FileHandler instance at 0x19ef320>
Handler level 0
Now in the middle of execution, you'll see that the logger's handler (hdlr) is interpreted as a str.
Started from <class 'mymodule.ext.freebase.HTTPMetawebSession'>.
Traceback (most recent call last):
File "hadoop/get_web_data.py", line 144, in <module>
main()
File "hadoop/get_web_data.py", line 121, in main
for count, performer in enumerate(results):
File "/home/wraith/dev/modules/mymodule/ext/freebase.py", line 126, in mqlreaditer
r = self._httpreq_json(service, 'POST', form=dict(query=qstr))
File "/home/wraith/dev/modules/mymodule/contrib/freebase/api/session.py", line 369, in _httpreq_json
resp, body = self._httpreq(*args, **kws)
File "/home/wraith/dev/modules/mymodule/contrib/freebase/api/session.py", line 346, in _httpreq
self.log.info('%s %s%s%s', method, url, formstr, headerstr)
File "/usr/lib/python2.5/logging/__init__.py", line 985, in info
apply(self._log, (INFO, msg, args), kwargs)
File "/usr/lib/python2.5/logging/__init__.py", line 1101, in _log
self.handle(record)
File "/usr/lib/python2.5/logging/__init__.py", line 1111, in handle
self.callHandlers(record)
File "/usr/lib/python2.5/logging/__init__.py", line 1147, in callHandlers
if record.levelno >= hdlr.level:
AttributeError: 'str' object has no attribute 'level'
In the last 2 lines, hdlr.level blows up because hdlr is not a str.
if record.levelno >= hdlr.level:
AttributeError: 'str' object has no attribute 'level'
After setting the handler at the beginning, which is fine, I do not add another handler or alter the existing in any way. The only command I call on logger is logger.info('event to log')
.
What would alter the logger's handler in this way?