Correctly handle the case where sys.stdout is closed.

This commit is contained in:
Jeremy Fincher 2004-04-06 09:32:09 +00:00
parent 5f53515a54
commit 9cfed8f0d3

View File

@ -74,9 +74,23 @@ class BetterStreamHandler(logging.StreamHandler):
class StdoutStreamHandler(BetterStreamHandler):
def disable(self):
self.setLevel(sys.maxint) # Just in case.
_logger.removeHandler(self)
logging._acquireLock()
try:
del logging._handlers[self]
finally:
logging._releaseLock()
def emit(self, record):
if conf.supybot.log.stdout():
BetterStreamHandler.emit(self, record)
try:
BetterStreamHandler.emit(self, record)
except ValueError, e: # Raised if sys.stdout is closed.
self.disable()
error('Error logging to stdout. Removing stdout handler.')
exception('Uncaught exception in StdoutStreamHandler:')
class BetterFileHandler(logging.FileHandler):