Last active
May 3, 2025 02:49
-
-
Save murarisumit/75b0d3df0d611e135030a33c048ed9e3 to your computer and use it in GitHub Desktop.
basic logging python #python #logging
This file contains hidden or 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
# `ref: https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/ | |
import logging | |
logger = logging.getLogger(__name__) | |
logger.setLevel(logging.INFO) | |
# create a file handler | |
handler = logging.FileHandler('hello.log') | |
handler.setLevel(logging.INFO) | |
# create a logging format | |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
handler.setFormatter(formatter) | |
# add the handlers to the logger | |
logger.addHandler(handler) | |
logger.info('Hello baby') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment