mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
Correctly handle the case where sys.stdout is closed.
This commit is contained in:
parent
5f53515a54
commit
9cfed8f0d3
16
src/log.py
16
src/log.py
@ -74,9 +74,23 @@ class BetterStreamHandler(logging.StreamHandler):
|
|||||||
|
|
||||||
|
|
||||||
class StdoutStreamHandler(BetterStreamHandler):
|
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):
|
def emit(self, record):
|
||||||
if conf.supybot.log.stdout():
|
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):
|
class BetterFileHandler(logging.FileHandler):
|
||||||
|
Loading…
Reference in New Issue
Block a user