Created
March 14, 2018 06:16
-
-
Save utahka/3f895d7de70689fdeba48c2f5f1e031b to your computer and use it in GitHub Desktop.
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 datetime | |
from logging import getLogger, Formatter, FileHandler, StreamHandler, DEBUG | |
today = datetime.date.today() | |
today = today.strftime("%Y%m%d") | |
# Specify a path to log file which will be written log messages | |
path_to_log = f"log/{today}.log" | |
fmt = "%(asctime)s %(name)s %(lineno)d [%(levelname)s][%(funcName)s] %(message)s" | |
log_fmt = Formatter(fmt) | |
# create a logger | |
logger = getLogger(__name__) | |
handler = StreamHandler() | |
handler.setLevel("INFO") | |
handler.setFormatter(log_fmt) | |
logger.addHandler(handler) | |
handler = FileHandler(path_to_log, 'a') | |
handler.setLevel(DEBUG) | |
handler.setFormatter(log_fmt) | |
logger.setLevel(DEBUG) | |
logger.addHandler(handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment