Skip to content

Instantly share code, notes, and snippets.

@dokenzy
Created January 9, 2017 07:51
Show Gist options
  • Save dokenzy/ea098f52a7ea05ea1382b1c0a33a403e to your computer and use it in GitHub Desktop.
Save dokenzy/ea098f52a7ea05ea1382b1c0a33a403e to your computer and use it in GitHub Desktop.
파이썬 3.4 로거
from datetime import datetime
import logging
import sys
from version import VERSION
def create_logger():
""" logging 객체를 만들어서 리턴한다.
:return: logging 객체
:rtype: logging
"""
logger = logging.getLogger()
now = datetime.now()
log_file_name = '{}.log'.format(now.strftime('%Y-%m-%d %H-%M-%S'))
file_handler = logging.FileHandler(log_file_name)
stream_handler = logging.StreamHandler(sys.stderr)
formatter = logging.Formatter('{} %(levelname)s %(filename)-12s Line:%(lineno)-8s %(message)s'.format(VERSION))
# 프로그램 업데이트가 잦기 때문에 버전 정보를 추가해 준다.
file_handler.setFormatter(formatter)
stream_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.addHandler(stream_handler)
logger.setLevel(logging.DEBUG)
return logger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment