준호씨의 블로그

python - logging 본문

개발이야기

python - logging

준호씨 2018. 4. 24. 23:46
반응형
import logging

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')
logging.info("test")

import logging
import time

today = time.strftime("%Y%m%d")
logger = logging.getLogger('myapp')

logdir = "."
logpath = logdir + '/logtest2.' + today + '.log'

hdlr = logging.FileHandler(logpath)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)

# DEBUG, INFO, WARNING, ERROR, CRITICAL
logger.setLevel(logging.DEBUG)

logger.debug("test")

참고

반응형
Comments