Created
October 28, 2024 06:45
-
-
Save rajvermacas/a2aed889f9effa4391b20923bb9c8173 to your computer and use it in GitHub Desktop.
python_logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
# Create a custom logger for your project | |
my_logger = logging.getLogger('my_project') | |
my_logger.setLevel(logging.DEBUG) | |
# Create a handler | |
console_handler = logging.StreamHandler() | |
console_handler.setLevel(logging.DEBUG) | |
# Create a formatter and add it to the handler | |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
console_handler.setFormatter(formatter) | |
# Add the handler to the logger | |
my_logger.addHandler(console_handler) | |
# External libraries will not flood the log | |
logging.getLogger('psparser').setLevel(logging.WARNING) | |
# Log messages with your custom logger | |
my_logger.debug("Debug message from my_project") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment