[New-bugs-announce] [issue14031] logging module cannot format str.format log messages

Guido Kollerie report at bugs.python.org
Thu Feb 16 16:20:49 CET 2012


New submission from Guido Kollerie <guido at kollerie.com>:

When logging messages with variable data one typically writes:

    username = 'Guido'
    logging.info('User %s logged in', username)

However Python 3 has support str.format (PEP 3101). If one has adopted str.format for formatting strings in Python 3 code one should also be able to write the above as:

    logging.info('User {} logged in', username)

However this currently is not supported. For backwards compatibility,% style logging should remain the default. However when a logger is configured using:

    import logging
    logging.basicConfig(style='{', format='{levelname}:{message}')

all subsequent calls to logging.debug, logging.info, logging.warning, logging.error, logging.critical, logging.exception and logging.log should use str.format for formatting.

----------
messages: 153481
nosy: gkoller
priority: normal
severity: normal
status: open
title: logging module cannot format str.format log messages
type: enhancement
versions: Python 3.2

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


More information about the New-bugs-announce mailing list