Search code examples
pythonunixloggingformattingpylint

Following Python Lazy Logging Formatting, but pylint is still showing (logging-not-lazy) messages


I'm logging some info messages and wanted to make sure I was following the PEP standards. Pylint says that this line:

        LOG.info('Directories have been made in /home/bushbak2/projects/'+
                 'system_file_audit/%s/', manu)

Is not following the lazy logging format of python. Could it be because the line carries over?

This is the message I get from pylint:

auto_audit.py:157:8: W1201: Use lazy % formatting in logging functions (logging-not-lazy)

Why does pylint still raise this message? Am I not appropriately following the PEP standard?

Cheers,

Brendan


Solution

  • Your problem comes from the + in your expression. Pylint sees it as a string concatenation and thus, recommends you to do this concatenation lazily.

    You can fix it by removing the +:

    LOG.info('Directories have been made in /home/bushbak2/projects/'
                     'system_file_audit/%s/', manu)