logger - choisungwook/portfolio GitHub Wiki

๊ฐœ์š”

ํŒŒ์ด์ฌ ๋กœ๊น…์„ yamlํŒŒ์ผ๋กœ ์„ค์ •ํ•˜๊ณ  ๋กœ๋“œ


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]

logging ์„ค์ • ๋กœ๋“œ

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?")
โš ๏ธ **GitHub.com Fallback** โš ๏ธ