[New-bugs-announce] [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:

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)

In the 3.3.4 release the strucutre of the 
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}")


logging._STYLES['{'][0]("{module} DEBUG: {lineno}: {message}")


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>

More information about the New-bugs-announce mailing list