Skip to content
This repository was archived by the owner on Feb 26, 2019. It is now read-only.

Commit 741c37d

Browse files
turn off TUF and in-toto console logging by default
* but you can turn it back on using the TUF_ENABLE_LOGGING env var * also use `logger` instead of `logging` everywhere
1 parent 76afbf5 commit 741c37d

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/pip/_internal/download.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,8 @@ def __init__(self, path_to_tuf_config_file):
139139
os.environ.get('TUF_ENABLE_LOGGING', False)
140140

141141
if enable_logging:
142-
# https://github.com/theupdateframework/tuf/pull/749
143-
log_filename = os.path.join(tuf.settings.repositories_directory,
144-
tuf_config['repository_dir'],
145-
'tuf.log')
146-
tuf.log.enable_file_logging(log_filename)
142+
# NOTE: Also set TUF output to DEBUG and above.
143+
logging.getLogger("tuf").setLevel(logging.DEBUG)
147144

148145
# Also set verbose, non-quiet in-toto logging.
149146
# https://github.com/in-toto/in-toto/blob/8eb8eab8c94f47e67a24b5e7d56f4519092dd9d2/in_toto/in_toto_verify.py#L205
@@ -290,7 +287,7 @@ def __verify_in_toto_metadata(self, target_relpath,
290287
params = self.__substitute_parameters(target_relpath)
291288
verifylib.in_toto_verify(layout, layout_key_dict,
292289
substitution_parameters=params)
293-
logging.info('E2E verified {}'.format(target_relpath))
290+
logger.info('in-toto verified {}'.format(target_relpath))
294291
except:
295292
logger.exception('in-toto failed to verify {}'\
296293
.format(target_relpath))
@@ -326,9 +323,7 @@ def _get_target(self, target_relpath, download_in_toto_metadata=True):
326323

327324
# Either the target has not been updated...
328325
if not len(updated_targets):
329-
logger.info('{} has not been updated'\
330-
.format(target_relpath))
331-
326+
logger.debug('{} has not been updated'.format(target_relpath))
332327
# or, it has been updated, in which case...
333328
else:
334329
# First, we use TUF to download and verify the target.
@@ -337,6 +332,8 @@ def _get_target(self, target_relpath, download_in_toto_metadata=True):
337332
assert updated_target == target
338333
self.__updater.download_target(updated_target, self.__targets_dir)
339334

335+
logger.info('TUF verified {}'.format(target_relpath))
336+
340337
# Next, we use in-toto to verify the supply chain of the target.
341338
# NOTE: We use a flag to avoid recursively downloading in-toto
342339
# metadata for in-toto metadata themselves, and so on ad infinitum.
@@ -355,8 +352,8 @@ def _get_target(self, target_relpath, download_in_toto_metadata=True):
355352
not target_relpath.endswith('.html'):
356353
self.__download_and_verify_in_toto_metadata(target, target_relpath)
357354
else:
358-
logging.warning('Switched off in-toto verification for {}'\
359-
.format(target_relpath))
355+
logger.warning('Switched off in-toto verification for {}'\
356+
.format(target_relpath))
360357

361358
target_path = os.path.join(self.__targets_dir, target_relpath)
362359
return target_path
@@ -385,12 +382,12 @@ def download(self, target_relpath, dest_dir, dest_filename):
385382
import tuf.log
386383
import tuf.settings
387384

388-
# NOTE: By default, we turn off TUF logging, and use the pip log instead.
389-
# You may turn toggle this behaviour using the "enable_logging" flag in the
390-
# TUF configuration file.
385+
# We *always* turn off TUF logging.
391386
tuf.settings.ENABLE_FILE_LOGGING = False
392-
# NOTE: We set the TUF console logging level to CRITICAL and above.
387+
# By default, set the TUF console logging level to >= CRITICAL.
393388
logging.getLogger("tuf").setLevel(logging.CRITICAL)
389+
# Also set non-verbose, quiet in-toto logging.
390+
logging.getLogger("in_toto").setLevelVerboseOrQuiet(False, True)
394391
from tuf.client.updater import Updater
395392

396393
from in_toto import verifylib

0 commit comments

Comments
 (0)