Skip to content

logger: use logging format interpolation #1843

@ghost

Description

E.g.

logger.debug("Saving {} to {}.".format(path_info, to_info))

should be

logger.debug("Saving '%s' to '%s'.", path_info, to_info)

As suggested by @ei-grad in this PR: #1822

Reference: https://docs.python.org/3/howto/logging.html#optimization

It needs to support braces {} formatting, you can use a log adapter for Python 2.7:
```python
import logging

class Message(object):
def init(self, fmt, args):
self.fmt = fmt
self.args = args

def __str__(self):
    return self.fmt.format(*self.args)

class StyleAdapter(logging.LoggerAdapter):
def init(self, logger, extra=None):
super(StyleAdapter, self).init(logger, extra or {})

def log(self, level, msg, *args, **kwargs):
    if self.isEnabledFor(level):
        msg, kwargs = self.process(msg, kwargs)
        self.logger._log(level, Message(msg, args), (), **kwargs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions