logger - choisungwook/portfolio GitHub Wiki
파이썬 로깅을 yaml파일로 설정하고 로드
# reference: https://docs.python.org/ko/3/howto/logging.html
version: 1
formatters:
simple:
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: simple
stream: ext://sys.stdout
loggers:
simple:
level: DEBUG
handlers: [console]
propagate: no
root:
level: DEBUG
handlers: [console]
import yaml
import logging.config
import logging
try:
with open('config.yaml', 'r') as f:
config = yaml.safe_load(f)
# reference: https://stackoverflow.com/questions/49012123/python3-logging-yaml-configuration
logging.config.dictConfig(config)
log = logging.getLogger('simple')
except Exception as e:
print("[-] Error: import logging yaml is failed")
# example
# log.debug("do you see me?")