lib389 calls logging.basicConfig() at several places at module scope level. This causes imports from these modules to add an unwanted handler to the root logger of the python's standard logging module.
logging.basicConfig()
logging
If any script has its own settings of the logging module and wants to use the lib389 library, the above code will cause it to possibly duplicate all of the output. This can be observed e.g. during FreeIPA master install with code from https://github.com/freeipa/freeipa/pull/1563.
master
>>> import logging >>> l = logging.getLogger() >>> l.handlers [] >>> import lib389
>>> l.handlers [<StreamHandler <stderr> (NOTSET)>]
Logging setup should not happen at the library level but merely at the level of the scripts that require lib389 to run.
>>> l.handlers []
Was not able to set up testing environment properly so the patches are unfortunately untested :/
<img alt="0001-lib389-remove-unused-imports-in-__init__.py.patch" src="/389-ds-base/issue/raw/files/ca76365119d2156b9660ed0726b9dd27915e87a705a1632b178ba9a76cdb23b3-0001-lib389-remove-unused-imports-in-__init__.py.patch" /><img alt="0002-lib389-don-t-set-up-logging-at-module-scope.patch" src="/389-ds-base/issue/raw/files/87a67298c8d3507ca84659e57c14e062c2462d44c5564f96b64a47df1c209ada-0002-lib389-don-t-set-up-logging-at-module-scope.patch" />
The patches are based on top of the one in https://pagure.io/389-ds-base/issue/49835
Thank you for the patch!
Okay, currently, if we remove these lines from the core lib389:
-logging.basicConfig(level=logging.DEBUG)
Then we don't have any logging during the test run with '-s': py.test -s -v dirsrvtests/tests/suites/replication/acceptance_test.py
py.test -s -v dirsrvtests/tests/suites/replication/acceptance_test.py
So it looks like we should have 'basicConfig' somewhere for the tests. I think we can add it here - https://pagure.io/389-ds-base/blob/master/f/src/lib389/lib389/topologies.py#_24 Will it work for the IPA case?
Metadata Update from @spichugi: - Custom field component adjusted to None - Custom field origin adjusted to None - Custom field reviewstatus adjusted to None - Custom field type adjusted to None - Custom field version adjusted to None
If you want logging in tests, and I do not understand the rationale behind that since pytest + your own library logging should give you all you need if designed properly, create a script that would run your tests and setup logging for you. It can't be anywhere in module scope.
If you need to configure logging for tests, then you should either follow Standa's advise, configure logging in a conftest.py file, or use one of the pytest logging plugins.
PS: A library must never configure logging. It's the responsibility of an application or script to configure logging. A library should only create loggers and call logging functions on the logger. Output, formatting, filtering, et al is the job of an application.
Metadata Update from @mreynolds: - Issue set to the milestone: 1.4.0
https://pagure.io/389-ds-base/pull-request/49853
PR was merged, should this issue be closed, then?
Yup
Metadata Update from @mreynolds: - Issue close_status updated to: fixed - Issue status updated to: Closed (was: Open)
389-ds-base is moving from Pagure to Github. This means that new issues and pull requests will be accepted only in 389-ds-base's github repository.
This issue has been cloned to Github and is available here: - https://github.com/389ds/389-ds-base/issues/2903
If you want to receive further updates on the issue, please navigate to the github issue and click on subscribe button.
subscribe
Thank you for understanding. We apologize for all inconvenience.
Metadata Update from @spichugi: - Issue close_status updated to: wontfix (was: fixed)
Login to comment on this ticket.