-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefix user_log (--log) entries with timestamp (#6142)
Why? Eases post-facto analysis of time spent in different phases of pip operation. Historical note: 767d11e#diff-b670e3b192038c9ffe810c1a12c0c51fL219 made it so that pip invocations emit zero timestamp information to the log file. Prior to that each pip invocation's start time was written out (search that commit's diff for [strftime]). Result: https://gist.github.com/fischman/f570886219de5c64a3b695300195c70a Resolves #6141
- Loading branch information
Showing
4 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Prefix pip's ``--log`` file lines with their timestamp. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import logging | ||
import os | ||
import time | ||
|
||
from pip._internal.utils.logging import IndentingFormatter | ||
|
||
|
||
class TestIndentingFormatter(object): | ||
""" | ||
Test `pip._internal.utils.logging.IndentingFormatter`. | ||
""" | ||
|
||
def setup(self): | ||
# Robustify the tests below to the ambient timezone by setting it | ||
# explicitly here. | ||
self.old_tz = getattr(os.environ, 'TZ', None) | ||
os.environ['TZ'] = 'UTC' | ||
# time.tzset() is not implemented on some platforms (notably, Windows). | ||
if hasattr(time, 'tzset'): | ||
time.tzset() | ||
|
||
def teardown(self): | ||
if self.old_tz: | ||
os.environ['TZ'] = self.old_tz | ||
else: | ||
del os.environ['TZ'] | ||
if 'tzset' in dir(time): | ||
time.tzset() | ||
|
||
def test_format(self, tmpdir): | ||
record = logging.makeLogRecord(dict( | ||
created=1547704837.4, | ||
msg='hello\nworld', | ||
)) | ||
f = IndentingFormatter(fmt="%(message)s") | ||
assert f.format(record) == 'hello\nworld' | ||
|
||
def test_format_with_timestamp(self, tmpdir): | ||
record = logging.makeLogRecord(dict( | ||
created=1547704837.4, | ||
msg='hello\nworld', | ||
)) | ||
f = IndentingFormatter(fmt="%(message)s", add_timestamp=True) | ||
expected = '2019-01-17T06:00:37 hello\n2019-01-17T06:00:37 world' | ||
assert f.format(record) == expected |