Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix increasing the root logging level by log-capture #987

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

janoskut
Copy link

Commit Message

Log-capturing used to set the root logger level to the configured capturing level, so that it is sufficiently low to capture the desired level.
However when the root logging level is already lower, this will in fact increase the level, changing the level of all other registered handlers.

This change fixes this: Not to directly set the root logging level, but instead only decrease it if necessary.

Discussion

Honestly, I don't think that the root level should be touched at all in here. For me it seems like that behave assumes that there will ever be only one of those 2 handlers: the capturing handler, or the default stream handler.

However, as soon as someone (like me) needs to use other handlers, such as file handlers, the root level must not be changed, otherwise those other handlers don't get to see the level they're configured for.

See the before_all() code in the feature file. This is the only way I came up with to support:

  • logging DEBUG level into a file
  • capturing a configured level (e.g. INFO) in capture-mode
  • console output with a configured level (e.g. INFO) in non-capture-mode

Note that with this requirement I also can't use Configuration.setup_logging(), because this sets up the default stream handler which is tied to the root logging level. This function also manipulates the root level. I'm personally wondering, if this function is actually more harmful (=causing confusion) than that it is helpful. Also it hides the not too minor detail that no console handler is created (by logging.basicConfig()), when in --logcapture mode - because then, log_capture has already added a handler, and logging.basicConfig() only creates a handler when none is present yet.

Quite much hidden stuff in there... the above change (or removing setting the root logger) seems to be definitely required to allow users to manage the handlers freely.

@jenisys jenisys force-pushed the main branch 5 times, most recently from 6508bd4 to a4dd3fe Compare March 6, 2022 23:33
@jenisys jenisys force-pushed the main branch 2 times, most recently from 11ddaf9 to 5101465 Compare May 2, 2022 19:16
@janoskut janoskut force-pushed the fix-increasing-root-logging-level branch from 1d53ec0 to 0a855ab Compare October 26, 2022 14:44
@janoskut janoskut force-pushed the fix-increasing-root-logging-level branch from 0a855ab to b2c4f66 Compare December 21, 2022 16:35
@janoskut janoskut force-pushed the fix-increasing-root-logging-level branch from b2c4f66 to 57c2189 Compare December 21, 2022 17:17
janoskut and others added 2 commits December 21, 2022 18:27
Rationale:
In behave, loggers are usually initialized before "before_all()" and "setup_logging()" are invoked.
When using a file config, the default behavior of the logging module is to disable existing loggers (see warning in https://docs.python.org/3/howto/logging.html#configuring-logging).
Changing the default behavior to not disabling the existing loggers matches behaves logger users better.
By passing the **kwargs into "fileConfig()", we still allow all desired behaviors.
@janoskut janoskut force-pushed the fix-increasing-root-logging-level branch from 57c2189 to 7ee1286 Compare December 21, 2022 17:34
Janos Kutscherauer and others added 3 commits December 21, 2022 18:34
Changing the main argument parser to accept "unknown" args.
Let the Runner superclass parse "unknown" args into "extra args". The default Runner implementation doesn't accept any extra args, to restore the original semantics.
However, having that, custom Runner classes can now provide own argparsers to accept extra-args from the CLI.
ADD allowing extra CLI args to be passed to Runners
Log-capturing used to set the root logger level to the configured capturing level, so that it is sufficiently low to capture the desired level.
However when the root logging level is already lower, this will in fact increase the level, changing the level of all other registered handlers.

This change fixes this: Not to directly set the root logging level, but instead only decrease it if necessary.
@janoskut janoskut force-pushed the fix-increasing-root-logging-level branch from 7ee1286 to d410c86 Compare December 22, 2022 08:30
@jenisys
Copy link
Member

jenisys commented Dec 22, 2022

HINT:
This PR is currently no mergeable because it contains additional unrelated changes (at least by the last commit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants