You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importlogginglog=logging.getLogger(__name__)
deffoo():
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).
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.
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.
When we use
context.config.setup_logging(configfile=...)
, existing loggers are always overwritten by the new configuration. This is the default behavior by thelogging
module, and noted with a big warning in https://docs.python.org/3/howto/logging.html#configuring-logging:In
behave
, thebefore_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: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
tologging.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.
The text was updated successfully, but these errors were encountered: