Message211949
Hi,
I use the logging module and have created a custom formatter to format the log messages different for each logging level.
This was developed with 3.3.3.
When i upgraded to 3.3.4 it no longer worked.
I got the error
TypeError: 'tuple' object is not callable
Here is the original code.
class SpecialFormatter(logging.Formatter):
FORMATS = {logging.DEBUG : logging._STYLES['{']("{module} DEBUG: {lineno}: {message}"),
logging.ERROR : logging._STYLES['{']("{module} ERROR: {message}"),
logging.INFO : logging._STYLES['{']("{module}: {message}"),
'DEFAULT' : logging._STYLES['{']("{module}: {message}")}
def format(self, record):
# Ugly. Should be better
self._style = self.FORMATS.get(record.levelno, self.FORMATS['DEFAULT'])
return logging.Formatter.format(self, record)
hdlr = logging.StreamHandler(sys.stderr)
hdlr.setFormatter(SpecialFormatter())
logging.root.addHandler(hdlr)
logging.root.setLevel(logging.INFO)
In the 3.3.4 release the strucutre of the
logging._STYLES
changed in logging/__init__.py.
It changed from a value to a tuple.
Therefore the above code needed to change
logging._STYLES['{']("{module} DEBUG: {lineno}: {message}")
to
logging._STYLES['{'][0]("{module} DEBUG: {lineno}: {message}")
Derek |
|
Date |
User |
Action |
Args |
2014-02-22 20:31:55 | derekwallace | set | recipients:
+ derekwallace |
2014-02-22 20:31:55 | derekwallace | set | messageid: <1393101115.55.0.4326996305.issue20732@psf.upfronthosting.co.za> |
2014-02-22 20:31:55 | derekwallace | link | issue20732 messages |
2014-02-22 20:31:54 | derekwallace | create | |
|