Skip to content

qtm_rt affects the root logger #44

@weeebber

Description

@weeebber

Hello, when importing qtm_rt (qtm_rt/__innit__.py) it is affecting the root logger rather than the expected "qtm_rt" logger.
This therefore causes all subsequent logging calls from my program to duplicate output.

The following lines are the cause:

LEVEL = logging.DEBUG if LOG_LEVEL == "debug" else logging.INFO
logging.basicConfig(level=LEVEL, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")

Considering you are calling LOG = logging.getLogger("qtm_rt"), I dont think this was intended behaviour.

The following will correct the code to the expected behaviour:

LOG = logging.getLogger("qtm_rt")
LOG_LEVEL = os.getenv("QTM_LOGGING", "DEBUG")

# WIP - sanity check LOG_LEVEL?
# As of Python 3.2 you can use the string rather than level numeric value (i.e. DEBUG = 10)

# Configure qtm_rt logger
LOG.setLevel(LOG_LEVEL)

# Console handler with custom formatter
LOG_CONSOLE_HANDLER = logging.StreamHandler()
LOG_CONSOLE_HANDLER.setLevel(LOG_LEVEL)
LOG_CONSOLE_HANDLER.setFormatter(logging.Formatter("%(asctime)s\t%(levelno)s %(levelname)s\t%(filename)s\t%(funcName)s\t%(message)s"))
LOG.addHandler(LOG_CONSOLE_HANDLER)

And then in my program I can do the following. The below might be worth mentioning on the front page of the docs.

# Set QTM logging level to ERROR before importing
os.environ["QTM_LOGGING"] = "ERROR"
import qtm_rt

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