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

Logging module references inconsistent and unpracticable for configuration with other packages #923

Closed
fmigneault opened this issue Apr 20, 2024 · 2 comments · Fixed by #930
Assignees

Comments

@fmigneault
Copy link
Contributor

Some places use these references to obtain a logger:

import logging as log

OWSLib/owslib/wps.py

Lines 115 to 116 in 79909b4

from owslib.util import (testXMLValue, testXMLAttribute, build_get_url, clean_ows_url, dump, getTypedValue,
getNamespace, element_to_string, nspath, openURL, nspath_eval, log, Authentication)

log.info(element_to_string(rootElement))

This causes the log.<level> function called to use the root logger.

On the other hand, the following use a specific logger (resulting in owslib.wps):

LOGGER = logging.getLogger(__name__)

Because of this, there is no clean way to configure the logger all over owslib.
Even worst is that, when used inside another application, the root logger must often be silenced or raised to ERROR or WARNING level to avoid too much noise, since it can combine many other locations. This makes it unpractical to debug specific operations in owslib.

The logging references should be unified to all employ (at least) the owslib namespace instead of root.
A quick fix would be to replace import logging as log in owslib.util by the following:

import logging
log = logging.getLogger(__name__)

This way, any place "incorrectly" using the logging alias as log would at least transparently use a namespace'd logger instead.

Maybe there are other locations to patch, but I have not explored the full repository for other logging references.

@fmigneault fmigneault self-assigned this Apr 20, 2024
@tomkralidis
Copy link
Member

Ideally owslib.util.log should be removed and all code should use the LOGGER = logging.getLogger(__name__) approach. Would this work for you?

@fmigneault
Copy link
Contributor Author

Yes. This is the best to have a non-root configurable logger that can be retrieved from anywhere.

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 a pull request may close this issue.

2 participants