Commit 6fc26a35 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

Improve log message and use lazy logging

parent 1ae8107b
......@@ -157,9 +157,11 @@ class Signature:
self.config = config
self.logger = logger
def log(self, message):
def log(self, message, *args):
if self.logger is not None:
self.logger.debug(message)
self.logger.debug(message, *args)
elif args:
print(message % args)
else:
print(message)
......@@ -189,11 +191,11 @@ class Signature:
required_key_list=['timestamp'], strategy=strategy)
if download_metadata_dict:
self.log('File downloaded on temp %s' % path)
self.log('File downloaded in %s', path)
current_sha256 = self.get_file_hash(path)
if shacache.download(path=sha256path, required_key_list=['timestamp'],
strategy=strategy, is_sha256file=True):
self.log('File downloaded on temp. %s' % sha256path)
self.log('sha 256 downloaded in %s', sha256path)
with open(sha256path, 'rb') as f:
expected_sha256 = f.read()
......@@ -230,16 +232,16 @@ class Signature:
try:
if shacache.upload(path=path,
metadata_dict=metadata_dict):
self.log('Uploaded upload file to cache.')
self.log('Uploaded %s to cache (using %s key).', path, shacache.directory_key)
if shacache.upload(path=sha256path,
metadata_dict=metadata_dict, is_sha256file=True):
self.log('Uploaded sha256file file to cache.')
self.log('Uploaded %s to cache (using %s key).', sha256path, shacache.directory_key)
else:
self.log('Fail to upload sha256file file to cache.')
else:
self.log('Fail to upload file to cache.')
self.log('Fail to upload %s to cache.', path)
except Exception:
self.log('Unable to upload to cache:\n%s.' % traceback.format_exc())
self.log('Unable to upload to cache:\n%s.', traceback.format_exc())
return
def upload(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment