Issue 22482: logging: fileConfig doesn't support formatter styles (original) (raw)

In the logging module's config.py, see the _create_formatters(cp) method used by the fileConfig() method. Note that it pulls "format" and "datefmt" and submits these in the formatter constructor:

f = c(fs, dfs)

However, the Formatter constructor has a third argument for formatting style:

def init(self, fmt=None, datefmt=None, style='%')

Since the argument is not passed, ConfigParser-format logging configs must use %-style logging format masks. We'd prefer to use curlies.

Note that the code for the dictionary configurator does this correctly:

        fmt = config.get('format', None)
        dfmt = config.get('datefmt', None)
        style = config.get('style', '%')
        result = logging.Formatter(fmt, dfmt, style)

While fileConfig() is not deprecated, I'm not planning to enhance it, as the newer dictConfig() API offers better functionality overall. With dictConfig(), you do have support for alternative formatting styles.