support sub-second granularity/precision in --log-date-format
(strftime %f
)
#10991
Labels
good first issue
easy issue that is friendly to new contributor
plugin: logging
related to the logging builtin plugin
topic: config
related to config handling, argument parsing and config file
type: enhancement
new feature or API change, should be merged into features branch
tl;dr pytest processing strftime
%f
specifier from--log-*-date-format
arguments would allow me to accurately merge log messages from disparate sub-systemsWhat's the problem?
Tests I run have pytest log messages that print at the second granularity for the datetimestamp, e.g.
2023-05-11T13:45:34
. At the same time, other log file messages not generated by pytest print sub-second datetimestamps, e.g.2023-05-11T13:45:34.123
.When reviewing the various logs, there are many message from other system components that are printing many log messages per second. Because pytest log messages are lacking sub-second precision, I am unable to align pytest log messages within other system log messages.
contrived example
For example, the system-under-test generates a log file like:
and the driver of tests, pytest, generates a log file like:
The pytest log messages cannot be precisely ordered among the other log messages that occurred during the datetime second
2023-05-11T13:45:34
, there were many things that occurred in the other system components within that second.current confusion
Given the following pytest code
To add sub-second granularity, it seems sensible to add
%f
within the--log-cli-date-format
but then I see the confusing output of
pytest logging is ignoring the strftime
%f
specifier!pytest feature request
I want pytest log messages to print sub-second granularity, e.g. process strftime
%f
within--log-date-format="...%f..."
settings.Describe the solution you'd like
Support strftime
%f
specifier in the various settings for date-format, e.g.--log-date-format
,--log-cli-date-format
,--log-file-date-format
.In my complex testing system, this means all log messages would be printed to millisecond precision. This allows engineers investigating issues to more accurately merge disparate testing system logs by their natural ordering mechanism of a datetimestamp.
Alternative Solutions
I can set the
logging
format to include%(msecs)03d
.However, it's a little confusing to have to manipulate log datetimestamps by two different mechanisms,
--log-cli-format
and--log-cli-date-format
.example workaround
On the command-line run:
This prints datetimestamps with millisecond precision
Summary
It is more intuitive for pytest to process the Python strftime
%f
specifier within all--*-date-format
options.The text was updated successfully, but these errors were encountered: