python处理日志_python – 使用多处理进行日志记录

我有以下记录器类(作为logger.py):

import logging, logging.handlers

import config

log = logging.getLogger('myLog')

def start():

"Function sets up the logging environment."

log.setLevel(logging.DEBUG)

formatter = logging.Formatter(fmt='%(asctime)s [%(levelname)s] %(message)s', datefmt='%d-%m-%y %H:%M:%S')

if config.logfile_enable:

filehandler = logging.handlers.RotatingFileHandler(config.logfile_name, maxBytes=config.logfile_maxsize,backupCount=config.logfile_backupCount)

filehandler.setLevel(logging.DEBUG)

filehandler.setFormatter(formatter)

log.addHandler(filehandler)

console = logging.StreamHandler()

console.setLevel(logging.DEBUG)

console.setFormatter(logging.Formatter('[%(levelname)s] %(message)s')) # nicer format for console

log.addHandler(console)

# Levels are: debug, info, warning, error, critical.

log.debug("Started logging to %s [maxBytes: %d, backupCount: %d]" % (config.logfile_name, config.logfile_maxsize, config.logfile_backupCount))

def stop():

"Function closes and cleans up the logging environment."

logging.shutdown()

对于日志记录,我启动logger.start()一次,然后从任何项目文件的logger导入日志中导入.然后我在需要时使用log.debug()和log.error().

它在脚本的任何地方(不同的类,函数和文件)都可以正常工作,但它不适用于通过多处理类进行操作的不同进程.

我收到以下错误:无法找到记录器“myLog”的处理程序.

我能做什么?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值