[Python] Logging variable data with new format string

Discussão em 'Python' iniciado por Stack, Outubro 2, 2024.

  1. Stack

    Stack Membro Participativo

    I use logging facility for python 2.7.3. Documentation for this Python version say:


    the logging package pre-dates newer formatting options such as str.format() and string.Template. These newer formatting options are supported...
    ​

    I like 'new' format with curly braces. So i'm trying to do something like:

    log = logging.getLogger("some.logger")
    log.debug("format this message {0}", 1)


    And get error:


    TypeError: not all arguments converted during string formatting
    ​

    What I miss here?

    P.S. I don't want to use

    log.debug("format this message {0}".format(1))


    because in this case the message is always being formatted regardless of logger level.

    Continue reading...

Compartilhe esta Página