Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
logging.py: Don't change log level of the root logger to bigger numeric value #3307
When doing log capturing we need to temporary change the level of the root logger to be at least
If root logger level has smaller numeric value than
Our use case is the following:
This constraint is quite important for us, because DEBUG logs are quite a lot, and if we allow logging plugin to capture DEBUG logs we get memory issues in Jenkins, where the tests run.
in order to see if we could get by with just correct handler setup i ventured into the python logging package
can you please add a test and a change-log entry? i'm also pondering if we should target master or features, since its a slight behaviour change to get this right
2 times, most recently
Mar 14, 2018
Thanks @KKoukiou for the PR!
Your use case makes sense, but isn't a little confusing that
@thisch couldyou please weigh on this?
For those of you, who don't know what this PR is fixing:
Imagine you want to log to a file with a certain log-file-level (e.g. INFO) but don't want to pollute the live-log output (e.g. log-level ERROR) with too many log-messages. Then you can do the following
However, with pytest 3.4 only log messages with log-level>=ERROR are written to the log-file
I'll take a closer look at the implementation in the following days.
On the other hand, what I didn't like from first place is that when we use
What I consider as more normal behavior, is that all these "--log-level-*" options in pytest will actually only affect the levels of the handlers they are internally creating and nothing else. If the root logger that they are actually applied on, has
Wouldn't it be more clear if all these options where clearly creating only relevant handlers for the root logger and nothing else?
I bet there was some reason behind this decision, but I really don't see it now.
Thx @KKoukiou for your suggestion
Why do you think that this should be more normal behavior?
This is clear.
Why should the users modify the configuration of the root logger at all in
Can you come up with an example, which exposes the weaknesses of the
Unfortunately, I can't comment on that.
Here is another example which is fixed by this PR:
import logging logger = logging.getLogger() def test_foo(): logger.info('info text ' + 'going to logger') logger.warning('warning text ' + 'going to logger') logger.error('error text ' + 'going to logger') assert 0
Without this fix the following testrun does not show the info and the warning log message in the live log output
@KKoukiou please add this test also to the unittests
@thisch thanks for being open to this discussion. See answer inline.
See answer bellow.
Overwritting the root logger configuration from pytest, according to some
Additionally, when we in pytest overwrite the logger values and invalidate the
Lets say your tests use the following logging configuration file.
handlers: file: class : logging.FileHandler level: DEBUG filename: logconfig.log loggers: randomlogger: level: DEBUG handlers: - file propagate: 0 root: level: INFO handlers: - file
logconfig.log file will have DEBUG logs from randomlogger
If you 'll pass --log-level=DEBUG because someone decided that
This is example might not be the best, but my point is that I believe we should
PS: I know that we can use here log-file option and avoid this, but imagine root logger