path: root/anteater/src/get_lists.py
diff options
authorRoss Brattain <ross.b.brattain@intel.com>2017-06-21 21:51:49 -0700
committerRoss Brattain <ross.b.brattain@intel.com>2017-07-01 01:58:42 -0700
commitc1f9e57c68e7d77967bf94400afb228d72819eb7 (patch)
tree9ec786c2a88db367bd1b490e7afdfa42ff47ee44 /anteater/src/get_lists.py
parenteceefe7114bc5d0fc94ac77ee4e510c94c1a76bf (diff)
switch logging to proper usage
The logging methods do string interpolation themselves The first arg to logging.debug() is formally defined to be a message format string. From the reference: https://docs.python.org/2/library/logging.html#logging.Logger.debug Logger.debug(msg, *args, **kwargs) Logs a message with level DEBUG on this logger. The msg is the message format string, and the args are the arguments which are merged into msg using the string formatting operator. (Note that this means that you can use keywords in the format string, together with a single dictionary argument.) There are two keyword arguments in kwargs which are inspected: exc_info which, if it does not evaluate as false, causes exception information to be added to the logging message. If an exception tuple (in the format returned by sys.exc_info()) is provided, it is used; otherwise, sys.exc_info() is called to get the exception information The reason logging does string interpolation it self is to implement deferred interpolation. String interpolation involves evaluating arguments, so it can introduce significant computation. The logging module tries to be smart about deferring interpolation until the last possible moment. The logging methods check isEnabledFor for the log level and won't interpolate if the level is not enabled. https://github.com/python/cpython/blob/2.7/Lib/logging/__init__.py#L1178 def warning(self, msg, *args, **kwargs): if self.isEnabledFor(WARNING): self._log(WARNING, msg, args, **kwargs) logging actually waits to interpolate the string in LogRecord.getMessage() https://github.com/python/cpython/blob/2.7/Lib/logging/__init__.py#L328 if self.args: msg = msg % self.args Change-Id: I0090dcbc408200b6f2471748eae0c5a763da2e37 Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
Diffstat (limited to 'anteater/src/get_lists.py')
1 files changed, 4 insertions, 8 deletions
diff --git a/anteater/src/get_lists.py b/anteater/src/get_lists.py
index e27335a..024cef3 100644
--- a/anteater/src/get_lists.py
+++ b/anteater/src/get_lists.py
@@ -87,8 +87,7 @@ class GetLists(object):
binary_hash = (yl['binaries'][project][file_name])
return binary_hash
except KeyError:
- logger.info('No checksum entries found for {0}'.
- format(file_name))
+ logger.info('No checksum entries found for %s', file_name)
binary_hash = 'null'
return binary_hash
@@ -102,11 +101,9 @@ class GetLists(object):
logger.error('Key Error processing file_names list values')
project_list = set((yl['file_audits'][project]['file_names']))
- logger.info('file_names waivers found for {0}'.
- format(project))
+ logger.info('file_names waivers found for %s', project)
except KeyError:
- logger.info('No file_names waivers found for {0}'.
- format(project))
+ logger.info('No file_names waivers found for %s', project)
file_names_re = re.compile("|".join(default_list),
@@ -129,8 +126,7 @@ class GetLists(object):
project_list = set((yl['file_audits'][project]['file_contents']))
except KeyError:
- logger.info('No file_contents waivers found for {0}'.
- format(project))
+ logger.info('No file_contents waivers found for %s', project)
file_contents_re = re.compile("|".join(default_list),