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

Existing loggers are overwritten by file config #985

Open
janoskut opened this issue Dec 27, 2021 · 0 comments
Open

Existing loggers are overwritten by file config #985

janoskut opened this issue Dec 27, 2021 · 0 comments
Labels

Comments

@janoskut
Copy link

janoskut commented Dec 27, 2021

When we use context.config.setup_logging(configfile=...), existing loggers are always overwritten by the new configuration. This is the default behavior by the logging module, and noted with a big warning in https://docs.python.org/3/howto/logging.html#configuring-logging:

Warning: The fileConfig() function takes a default parameter, disable_existing_loggers, which defaults to True for reasons of backward compatibility. This may or may not be what you want, since it will cause any non-root loggers existing before the fileConfig() call to be disabled unless they (or an ancestor) are explicitly named in the configuration. Please refer to the reference documentation for more information, and specify False for this parameter if you wish.

In behave, the before_all() hook is normally invoked only after all other modules are imported, and hence after all file-global loggers are created. While it may be debatable, it is common practice to use file-global loggers such as:

import logging

log = logging.getLogger(__name__)

def foo():
    log.info('using the global logger')

When using such modules in behave with file-config, those global loggers are overwritten, and all modules which use such loggers (e.g. step definitions, or from the system under test) won't provide logging.

I suggest to at least pass all **kwargs to logging.config.fileConfig(), to allow to overwrite this default behavior, or even more change the default behavior to "not disable existing loggers" (and still pass the kwargs to allow control of it).

See the #986.

janoskut pushed a commit to unumotors/behave that referenced this issue Dec 27, 2021
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.
@jenisys jenisys added the minor label Jan 9, 2022
janoskut pushed a commit to unumotors/behave that referenced this issue Oct 26, 2022
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 pushed a commit to unumotors/behave that referenced this issue Dec 21, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants