python里的logging怎么写多个文件
1个回答
展开全部
an example:
# coding: utf-8
# filename: cfg/logger.yml
version: 1
formatters:
simple:
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
consolefmt:
format: '%(name)s - %(levelname)s - %(message)s'
handlers:
console:
class : logging.StreamHandler
formatter: consolefmt
level : WARNING
stream : ext://sys.stdout
ownerloggerfile:
class : logging.handlers.RotatingFileHandler
formatter: simple
level : INFO
filename: log/billingcodeowner.log
maxBytes: 1048576
backupCount: 3
phnloggerfile:
class : logging.handlers.RotatingFileHandler
formatter: simple
level : INFO
filename: log/phnparser.log
maxBytes: 1048576
backupCount: 3
loggers:
billingcodeowner:
level: DEBUG
handlers: [ownerloggerfile]
propagate: no
phoneparser:
level: DEBUG
handlers: [console, phnloggerfile]
propagate: no
root:
level: DEBUG
handlers: [console,phnloggerfile]
usage in python application:
import logging
import logging.config
import codecs
import yaml
logging.config.dictConfig(codecs.open("cfg/logger.yml", 'r', 'utf-8').read())
logger = logging.getLogger("billingcodeowner")
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询