Replies: 1 comment
-
I have the same concern. In addition, I have tried using a custom formatter by running pytest.main() from within a python script. In the script, I import a logging package I've uploaded to pypi (https://pypi.org/project/jsonloggeriso8601datetime/). First thing I do in the script is import and configure that package. That should set the custom formatters on the configured console and file handlers on the root logger. The issue I'm seeing is with levels. when I set log_cli to true in pyproject.toml, the log_cli_level seems to have precedence over my custom handler level. for the file handler though, the level of my custom handler is honored. I'm assuming this is due to log_cli. And it makes sense. I've been digging around in this way too long. I'm going to go with keeping pytest config in pyproject.toml and accept that logs from pytest runs not using my little wrapper script will be different. Considering the amount of attention this has seen in the last year, it seems like others are not as concerned with native configuration options for logging timestamps. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I think I've found a "dark corner" of python logging + pytest.
Problem:
Of course I can solve any and all of those problems programmatically by creating a new, custom formatter in Python; but I'd like to understand if I can achieve this result only with settings in
pytest.ini
(or pyproject, or pytest command line) - I'm trying to centralize logging configuration, and I don't want to overlap and mingle pytest + programmatic settings.Suppose it's April 27th 2022, 13.40.00.123 CEST (UTC+2). I'd like my logs to contain either:
2022-04-27 13.40.00.123+02:00
or
2022-04-27 11.40.00.123Z
So, I need milliseconds, but I need the proper complete time as well. I'm currently able to obtain:
2022-04-27 13.40.00.123
(using logging msecs formatter) but it's without timezone; and if I want the timezone, I could get2022-04-27 13.40.00+02:00.123
(because the timezone is part of the date format, while msecs are part of the logrecord format).Any idea?
Would pytesters be open to a config like
log_cli_formatter = somepackage.somemodule.SomeCustomFormatter
if I submit a PR?Thanks,
Alan
Beta Was this translation helpful? Give feedback.
All reactions