#49844 lib389: don't setup logs in the module scope
Closed: wontfix 3 years ago Opened 3 years ago by stlaz.

Issue Description

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.

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.

Package Version and Platform

master

Steps to reproduce

>>> import logging
>>> l = logging.getLogger()
>>> l.handlers
[]
>>> import lib389

Actual results

>>> l.handlers
[<StreamHandler <stderr> (NOTSET)>]

Expected results

Logging setup should not happen at the library level but merely at the level of the scripts that require lib389 to run.

>>> l.handlers
[]

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

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

3 years ago

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

3 years ago

PR was merged, should this issue be closed, then?

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)

3 years ago

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.

Thank you for understanding. We apologize for all inconvenience.

Metadata Update from @spichugi:
- Issue close_status updated to: wontfix (was: fixed)

2 years ago

Login to comment on this ticket.

Metadata