2018-03-01

#default_log.yaml 

version: 1
formatters:
  simple:
    format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
  detail:
    format: '%(asctime)s - %(levelname)s - File: %(filename)s - %(funcName)s() - Line: %(lineno)d -  %(message)s'

loggers:
  all:
    handlers: [all]
    propagate: true
  warn:
    handlers: [warn]
    propagate: true
  ingenia:
    handlers: [ingenia]
    propagate: false  # We dont want ingenia logs going everywhere
    qualname: ingenia
  tomario:
    handlers: [all, console, error]
    propagate: false
  kafka_client:
    handlers: [all, console, error]
    propagate: false
  apscheduler:
    handlers: [all, console, error]
    propagate: false

handlers:
  console:
    class: logging.StreamHandler
    level: INFO
    formatter: simple
    stream: ext://sys.stdout
  all:
    class: logging.handlers.TimedRotatingFileHandler
    level: INFO
    formatter: simple
    interval: 1
    when: D
    backupCount: 90
    filename: /var/log/tomario/all.log
  warn:
    class: logging.handlers.TimedRotatingFileHandler
    level: WARNING
    formatter: detail
    interval: 1
    when: D
    backupCount: 90
    filename: /var/log/tomario/warn.log
  error:
    class: logging.handlers.TimedRotatingFileHandler
    level: ERROR
    formatter: detail
    interval: 1
    when: D
    backupCount: 90
    filename: /var/log/tomario/warn.log
  ingenia:
    class: logging.handlers.TimedRotatingFileHandler
    level: DEBUG
    formatter: simple
    interval: 1
    when: D
    backupCount: 90
    filename: /var/log/tomario/ingenia.log

root:
  level: INFO
  handlers: [console, all, warn]
  propagate: true
#log.py


#-*-coding:utf-8-*-
#Date:  2017-02-28
#Auth:  zhaojunwang272

import os
import yaml
import logging.config

LOGPATH = ("d:/var/log" if os.path.exists("d:/var/log") else '/var/log') + '/tomario'
if not os.path.exists(LOGPATH): os.makedirs(LOGPATH)
yaml_file = os.path.join(os.path.dirname(__file__), 'yamls/default_log.yaml')
logging.config.dictConfig(yaml.load(open(yaml_file, 'r')))

base_log  = logging.getLogger("tomario")
kafka_log = logging.getLogger("kafka_client")
apsl_log  = logging.getLogger("apscheduler")

你可能感兴趣的:(2018-03-01)