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

Commit 15e8dfa

Browse files
Merge pull request pypa#8 from DataDog/trishankatdatadog/18.1.tuf-in-toto.kill-console-logging
Turn off TUF + in-toto console logging by default
2 parents 6e4bc36 + 5db8c5c commit 15e8dfa

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

src/pip/_internal/download.py

+20-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
@@ -382,14 +379,22 @@ def download(self, target_relpath, dest_dir, dest_filename):
382379
if 'TUF_CONFIG_FILE' in os.environ:
383380
import glob
384381
import tempfile
385-
import tuf.settings
386382

387-
# NOTE: By default, we turn off TUF logging, and use the pip log instead.
388-
# You may turn toggle this behaviour using the "enable_logging" flag in the
389-
# TUF configuration file.
383+
# We always turn off TUF logging.
384+
import tuf.settings
390385
tuf.settings.ENABLE_FILE_LOGGING = False
386+
# By default, set the TUF console logging level to >= CRITICAL.
387+
import tuf.log
388+
logging.getLogger("tuf").setLevel(logging.CRITICAL)
389+
390+
# Import what we need from TUF.
391391
from tuf.client.updater import Updater
392392

393+
# Also set non-verbose, quiet in-toto logging.
394+
import in_toto.log
395+
logging.getLogger("in_toto").setLevelVerboseOrQuiet(False, True)
396+
397+
# Import what we need from in-toto.
393398
from in_toto import verifylib
394399
from in_toto.models.metadata import Metablock
395400
from in_toto.util import import_public_keys_from_files_as_dict

0 commit comments

Comments
 (0)