5 """This logger starts out with a default handler that writes to stdout 6 addHandler removes this default the first time another handler is added. 7 This is used for forcebalance package level logging, where a logger should 8 always be present unless otherwise specified. To silence, add a NullHandler 9 We also by default set the log level to INFO (logging.Logger starts at WARNING)""" 21 super(ForceBalanceLogger, self).
addHandler(hdlr)
25 if len(self.handlers)==0:
30 """Exactly like output.StreamHandler except it does no extra formatting 31 before sending logging messages to the stream. This is more compatible with 32 how output has been displayed in ForceBalance. Default stream has also been 33 changed from stderr to stdout""" 34 def __init__(self, stream = sys.stdout):
37 def emit(self, record):
38 message = record.getMessage()
39 self.stream.write(message)
43 """Exactly like output.FileHandler except it does no extra formatting 44 before sending logging messages to the file. This is more compatible with 45 how output has been displayed in ForceBalance.""" 46 def emit(self, record):
47 message = record.getMessage()
48 self.stream.write(message)
52 """Similar to RawStreamHandler except it does not write terminal escape codes. 53 Use this for 'plain' terminal output without any fancy colors or formatting""" 54 def __init__(self, stream = sys.stdout):
55 super(CleanStreamHandler, self).__init__(stream)
58 message = record.getMessage()
59 message = re.sub(
"\x1b\[[0-9][0-9]?;?[0-9]?[0-9]?m",
"", message)
60 self.stream.write(message)
64 """File handler that does not write terminal escape codes and carriage returns 65 to files. Use this when writing to a file that will probably not be viewed in a terminal""" 66 def emit(self, record):
67 message = record.getMessage()
68 message = re.sub(
"\x1b\[[0-9][0-9]?;?[0-9]?[0-9]?m",
"", message)
69 message = re.sub(
"\r",
"\n", message)
70 self.stream.write(message)
74 setLoggerClass(ForceBalanceLogger)
75 logger=getLogger(
'forcebalance')
79 def error(self, msg, *args, **kwargs):
80 msg =
'\n'.join([
'\x1b[91m%s\x1b[0m' % s
for s
in msg.split(
'\n')
if len(s.strip()) > 0])+
'\n' 81 for hdlr
in (self.parent.handlers
if self.propagate
else self.handlers):
82 if hasattr(hdlr,
'stream'):
83 hdlr.savestream = hdlr.stream
84 hdlr.stream = sys.stderr
85 super(ModLogger, self).
error(msg, *args, **kwargs)
86 for hdlr
in (self.parent.handlers
if self.propagate
else self.handlers):
87 if hasattr(hdlr,
'stream'):
88 hdlr.stream = hdlr.savestream
91 setLoggerClass(ModLogger)
def addHandler(self, hdlr)
Exactly like output.FileHandler except it does no extra formatting before sending logging messages to...
def removeHandler(self, hdlr)
File handler that does not write terminal escape codes and carriage returns to files.
def __init__(self, stream=sys.stdout)
def error(self, msg, args, kwargs)
Exactly like output.StreamHandler except it does no extra formatting before sending logging messages ...
Similar to RawStreamHandler except it does not write terminal escape codes.
This logger starts out with a default handler that writes to stdout addHandler removes this default t...