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

log.py should not configure logging.basicConfig() #19

Open
itguy19 opened this issue May 3, 2024 · 0 comments
Open

log.py should not configure logging.basicConfig() #19

itguy19 opened this issue May 3, 2024 · 0 comments

Comments

@itguy19
Copy link

itguy19 commented May 3, 2024

I needed the cloudscale-python-sdk, as well as logging in my new project. I configured logging as usual:

def configure_logging(log_file_path: str):
    logging.basicConfig(
        level=logging.DEBUG,
        filename=log_file_path,
        filemode="a",
        format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
    )

but this didn't seem to work. After two hours of debugging, I figured out that log.py configures logging.basicConfig() when I import the module. This was unexpected as I have not seen a module configure logging before.

To configure logging the way I want it to work, I need to import cloudscale AFTER I have configured my logging:
(works)

from logger import configure_logging, log_info

configure_logging("api.log")
import cloudscale

log_info("My logging!")

(doesn't work)

from logger import configure_logging, log_info

import cloudscale
configure_logging("api.log")

log_info("My logging!")

Importing cloudscale after I have configured logging works, but sadly results in pretty ugly code... I don't think the cloudscale-python-sdk should touch logging.basicConfig(), but if you have a better (intended) solution, please let me know. :)

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

1 participant