[Python-projects] Checker for use of the standard logging module
Nathaniel Manista
nathaniel at google.com
Thu Jun 11 01:58:02 CEST 2009
Pylint developers-
Another patch (this time wrapped up by "hg bundle"). Let me know what
you think.
Adds a checker for logging methods to pylint, flagging methods of the
form "logging.<method>(format_string % <format_args>)". Such methods should
be written as "logging.<method>(format_string, format_args)" with the
interpolation left to the logging method.
FALSE POSITIVE RISK: Low. Care is taken to ensure that only calls to
logging methods with a modulo operation in the appropriate argument position
are flagged. A numeric modulo operation yielding a value to be cast to a
string and logged ("logging.warn(5 % 3)", for example) would be a false
positive, but such code probably has larger problems.
FALSE NEGATIVE RISK: Moderate. The check is trivial to defeat on
purpose, but inadvertent false negatives should be few because it is
infrequent that any author would have legitimate reason to use logging in a
way that wouldn't be checked by the checker. Since this is a check for "best
practice" usage and not one that flags errors in code, an elevated
falsenegative
risk is acceptable - what's important is that every coder using the
anti-pattern see the lint message enough times to alter their coding
practices.
TESTED: A unit test is included with the checker.
-Nathaniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.logilab.org/pipermail/python-projects/attachments/20090610/bde1a869/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nathaniel_logging.bundle
Type: application/octet-stream
Size: 2627 bytes
Desc: not available
URL: <http://lists.logilab.org/pipermail/python-projects/attachments/20090610/bde1a869/attachment.obj>
More information about the Python-Projects
mailing list