Search code examples
pythonloggingpylintstring-interpolation

Logging format interpolation with multiple arguments


pylint produces the following warning:

logging-format-interpolation (W1202):

Use % formatting in logging functions and pass the % parameters as arguments Used when a logging statement has a call form of “logging.(format_string.format(format_args...))”. Such calls should use % formatting instead, but leave interpolation to the logging function by passing the parameters as arguments.

So the correct way of logging would be: logger.error('oops caused by %s', exc)

But how to pass multiple arguments? To have something like: logger.error('oops caused by %s %s') (where to put exc_one, exc_two?)


Solution

  • You should pass it as an ordinary positional arguments

    logger.error('oops caused by %s %s', exc_one, exc_two)

    See function signature: logging.error(msg, *args, **kwargs)