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

Logger config overrides client logger config #238

Open
uniqueg opened this issue May 20, 2023 · 6 comments
Open

Logger config overrides client logger config #238

uniqueg opened this issue May 20, 2023 · 6 comments

Comments

@uniqueg
Copy link

uniqueg commented May 20, 2023

Problem

When importing genomepy before setting a host application's logger config, genomepy's logging configuration is used instead.

Similar issues in other packages:

To reproduce

Put the following in a script:

#!/usr/bin/env python3
import logging

import genomepy

logging.basicConfig(level=logging.INFO, format="%(message)s")

LOGGER = logging.getLogger("my_script")
LOGGER.info("Log message")

Running the script yields:

Log message

Rerunning the script after removing the import genomepy line (or moving it after the logging.basicConfig() call) yields:

INFO:my_script:Log message

Expected result

Importing a package should not affect the host application's logging configuration, even when it is imported before the host logger is configured.

Possible resolution

Instead of configuring the genomepy logger configuration in the library, consider configuring it in the CLI entry point (module genomepy.cli) instead. That way, host applications consuming genomepy can configure their logger any way they want, while your intended logging behavior is set for users of the genomepy console script.

Workaround

A workaround is to import genomepy after configuring the host application's logger.

System info

OS version: Ubuntu 20.04.5 LTS
Python version: 3.7.12
genomepy version: 0.15.0

@siebrenf
Copy link
Member

Could you see if #241 fixes the issue? Unfortunately, I can't reproduce your issue! Here's what I tried:

scratch_12.py

#!/usr/bin/env python3
import logging
import genomepy

logging.basicConfig(level=logging.INFO, format="This is a logger message: %(message)s")

# promts a message
genomepy.manage_config("generate")

LOGGER = logging.getLogger("my_script")
LOGGER.info("Log message")

image

@uniqueg
Copy link
Author

uniqueg commented May 25, 2023

Strange...

With the exact same script I get the following output:

Created config file /home/uniqueg/.config/genomepy/genomepy.yaml
INFO:my_script:Log message

I'm at the airport, so no chance to try the PR right now, but will report back when I find the time. Thanks a lot.

@uniqueg
Copy link
Author

uniqueg commented May 25, 2023

Note that I installed genomepy via pip, not conda - maybe that makes a difference...

@uniqueg
Copy link
Author

uniqueg commented May 28, 2023

When installing dependencies via Mamba and then installing genomepy from the PR in #241 via pip install ., the genomepy logger does not hijack the manual logging config - neither in my test case nor in yours!

However, the situation is a little different, so I cannot say for sure whether it will fix the problem in the pip based installation...

@uniqueg
Copy link
Author

uniqueg commented May 28, 2023

In fact, when I check out the master branch and install via pip install ., I also cannot reproduce the issue I have reported. So either it's already fixed on the master branch OR it's really an issue that is specific to the installation from PyPI...

@siebrenf
Copy link
Member

I'm hoping the new version magically fixes this 🤞

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

No branches or pull requests

2 participants