-
-
Save dirkakrid/f710d1edd0b8e2c1c17199ddceb1d2dd to your computer and use it in GitHub Desktop.
basic logging python
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