Updated slightly, let's see if this helps.

This commit is contained in:
Jeremy Fincher 2004-05-11 22:29:29 +00:00
parent 9c4b80c653
commit 65c9ebc746

View File

@ -71,20 +71,8 @@ class Logger(logging.Logger):
self.error('Exception id: %s', eId) self.error('Exception id: %s', eId)
self.error('Exception string: %s', eStrId) self.error('Exception string: %s', eStrId)
class BetterStreamHandler(logging.StreamHandler):
def emit(self, record):
msg = self.format(record)
if not hasattr(types, "UnicodeType"): #if no unicode support...
self.stream.write("%s%s" % (msg, os.linesep))
else:
try:
self.stream.write("%s%s" % (msg, os.linesep))
except UnicodeError:
self.stream.write("%s%s" % (msg.encode("UTF-8"), os.linesep))
self.flush()
class StdoutStreamHandler(logging.StreamHandler):
class StdoutStreamHandler(BetterStreamHandler):
def disable(self): def disable(self):
self.setLevel(sys.maxint) # Just in case. self.setLevel(sys.maxint) # Just in case.
_logger.removeHandler(self) _logger.removeHandler(self)
@ -97,7 +85,7 @@ class StdoutStreamHandler(BetterStreamHandler):
def emit(self, record): def emit(self, record):
if conf.supybot.log.stdout() and not conf.daemonized: if conf.supybot.log.stdout() and not conf.daemonized:
try: try:
BetterStreamHandler.emit(self, record) logging.StreamHandler.emit(self, record)
except ValueError, e: # Raised if sys.stdout is closed. except ValueError, e: # Raised if sys.stdout is closed.
self.disable() self.disable()
error('Error logging to stdout. Removing stdout handler.') error('Error logging to stdout. Removing stdout handler.')