[issue20732] Custom logging formatter doesnt work in 3.3.4

Derek Wallace report at bugs.python.org
Sat Feb 22 21:31:55 CET 2014


New submission from Derek Wallace:

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

----------
components: Library (Lib)
messages: 211949
nosy: derekwallace
priority: normal
severity: normal
status: open
title: Custom logging formatter doesnt work in 3.3.4
type: behavior
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20732>
_______________________________________


More information about the Python-bugs-list mailing list