This commit is contained in:
Fabio Zadrozny 2021-11-04 09:42:05 -03:00
Родитель f139ed7a67
Коммит 30c150af91
5 изменённых файлов: 24 добавлений и 11 удалений

Просмотреть файл

@ -24,7 +24,7 @@
{
"Component": {
"Type": "pip",
"pip": { "Name": "pydevd", "Version": "2.6.0" }
"pip": { "Name": "pydevd", "Version": "2.7.0" }
},
"DevelopmentDependency": false
},

Просмотреть файл

@ -1,4 +1,4 @@
from _pydevd_bundle.pydevd_constants import DebugInfoHolder, SHOW_COMPILE_CYTHON_COMMAND_LINE, NULL
from _pydevd_bundle.pydevd_constants import DebugInfoHolder, SHOW_COMPILE_CYTHON_COMMAND_LINE, NULL, LOG_TIME
from contextlib import contextmanager
import traceback
import os
@ -90,6 +90,10 @@ def log_context(trace_level, stream):
_LoggingGlobals._debug_stream_initialized = original_initialized
import time
_last_log_time = time.time()
def _pydevd_log(level, msg, *args):
'''
Levels are:
@ -107,7 +111,15 @@ def _pydevd_log(level, msg, *args):
msg = msg % args
except:
msg = '%s - %s' % (msg, args)
msg = '%s\n' % (msg,)
if LOG_TIME:
global _last_log_time
new_log_time = time.time()
time_diff = new_log_time - _last_log_time
_last_log_time = new_log_time
msg = '%.2fs - %s\n' % (time_diff, msg,)
else:
msg = '%s\n' % (msg,)
try:
try:
initialize_debug_stream() # Do it as late as possible

Просмотреть файл

@ -272,6 +272,8 @@ USE_CYTHON_FLAG = os.getenv('PYDEVD_USE_CYTHON')
# Use to disable loading the lib to set tracing to all threads (default is using heuristics based on where we're running).
LOAD_NATIVE_LIB_FLAG = os.getenv('PYDEVD_LOAD_NATIVE_LIB', '').lower()
LOG_TIME = os.getenv('PYDEVD_LOG_TIME', 'true').lower() in ENV_TRUE_LOWER_VALUES
if USE_CYTHON_FLAG is not None:
USE_CYTHON_FLAG = USE_CYTHON_FLAG.lower()
if USE_CYTHON_FLAG not in ENV_TRUE_LOWER_VALUES and USE_CYTHON_FLAG not in ENV_FALSE_LOWER_VALUES:

Просмотреть файл

@ -98,7 +98,7 @@ from _pydevd_bundle.pydevd_thread_lifecycle import suspend_all_threads, mark_thr
if USE_CUSTOM_SYS_CURRENT_FRAMES_MAP:
from _pydevd_bundle.pydevd_constants import constructed_tid_to_last_frame
__version_info__ = (2, 6, 0)
__version_info__ = (2, 7, 0)
__version_info_str__ = []
for v in __version_info__:
__version_info_str__.append(str(v))

Просмотреть файл

@ -191,33 +191,32 @@ def test_pydevd_log():
pydev_log.critical('always')
pydev_log.info('never')
assert stream.getvalue() == 'always\n'
assert stream.getvalue().endswith('always\n')
stream = io.StringIO()
with log_context(1, stream=stream):
pydev_log.critical('always')
pydev_log.info('this too')
assert stream.getvalue() == 'always\nthis too\n'
assert stream.getvalue().endswith('always\n0.00s - this too\n')
stream = io.StringIO()
with log_context(0, stream=stream):
pydev_log.critical('always %s', 1)
assert stream.getvalue() == 'always 1\n'
assert stream.getvalue().endswith('always 1\n')
stream = io.StringIO()
with log_context(0, stream=stream):
pydev_log.critical('always %s %s', 1, 2)
assert stream.getvalue() == 'always 1 2\n'
assert stream.getvalue().endswith('always 1 2\n')
stream = io.StringIO()
with log_context(0, stream=stream):
pydev_log.critical('always %s %s', 1)
# Even if there's an error in the formatting, don't fail, just print the message and args.
assert stream.getvalue() == 'always %s %s - (1,)\n'
assert stream.getvalue().endswith('always %s %s - (1,)\n')
stream = io.StringIO()
with log_context(0, stream=stream):
@ -234,7 +233,7 @@ def test_pydevd_log():
pydev_log.error_once('always %s %s', 1)
# Even if there's an error in the formatting, don't fail, just print the message and args.
assert stream.getvalue() == 'always %s %s - (1,)\n'
assert stream.getvalue().endswith('always %s %s - (1,)\n')
def test_pydevd_logging_files(tmpdir):