Skip to content

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

Description

@itguy19

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. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions