Created
June 12, 2019 09:56
-
-
Save izikeros/50191789ffed98849300bd3ba6208b1e to your computer and use it in GitHub Desktop.
Setup logger printing to console and file.
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
import logger | |
import os | |
import time | |
LOG_NAME = 'app_name' | |
LOG_DIR = '../log' | |
log_fmt = '%(levelname).1s %(message)s' | |
logging.basicConfig(level=logging.DEBUG, format=log_fmt) | |
logger = logging.getLogger(__name__) | |
timestr = time.strftime("%Y%m%d-%H%M%S") | |
hdlr = logging.FileHandler(os.path.join(LOG_DIR, f'{LOG_NAME}_{timestr}.log')) | |
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') | |
hdlr.setFormatter(formatter) | |
logger.addHandler(hdlr) | |
logger.setLevel(logging.DEBUG) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment