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

Set log level in each module instead of using logging.basicConfig #478

Merged
merged 1 commit into from
Jan 10, 2022

Conversation

rpmanser
Copy link
Contributor

Description Of Changes

This PR sets the logging level using the module-level loggers instead of using logging.basicConfig(level=).

Running grep -Rn logging.basicConfig --include=*.py in the root directory of the repo should return nothing now. To check that this solved the issue, try running the following code without the changes, and then with the changes:

import logging
from siphon.catalog import TDSCatalog

logger = logging.getLogger(__name__)
logger.setLevel("INFO")

stream_handler = logging.StreamHandler()

formatter = logging.Formatter(
    fmt="%(asctime)s - $(levelname)s - %(message)s",
    datefmt="%Y-%m-%d %H:%M:%S",
)
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)

logger.debug("This is a debug test")
logger.info("This is an info test")
logger.warning("This is a warning test")
logger.error("This is an error test")
logger.critical("This is a critical test")

try:
    print(does_not_exist)
except NameError:
    logger.exception("This is an exception test")

Without the changes, two log messages should appear for each logger call greater than debug. One message will be formatted according to the formatter in the code above and the other will be unformatted. With the changes, only the formatted log messages should appear.

Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Importing siphon.catalog messes up logging
2 participants