我正在尝试将RotatingFile Handler扩展为FooBar。
class FooBar(RotatingFileHandler) : def __init__(self, filename, mode='a', maxBytes=0,backupCount=0, encoding=None, delay=0) : RotatingHandler.__init__(self, filename, mode, maxBytes, backupCount, encoding, delay)
我使用
配置它LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'formatters': { 'verbose': { 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' }, 'simple': { 'format': '%(levelname)s %(asctime)s %(message)s' }, }, 'handlers': { 'file':{ 'level': 'ERROR', 'class': 'myhandler.FooBar', 'formatter': 'simple', 'filename': '/tmp/cattle.txt', 'mode': 'a', 'maxBytes': 16, 'backupCount' : 100, }, #-- Remaining part truncated ### logging.config.dictConfig(LOGGING) ### === ERROR here
当我使用它时;我收到错误
File "/usr/lib/python2.7/logging/config.py", line 576, in configure '%r: %s' % (name, e)) ValueError: Unable to configure handler 'file': global name 'RotatingHandler' is not defined
答案 0 :(得分:2)
RotatingHandler
不在范围内,因此您需要这样的内容才能将其纳入范围:
from logging.handlers import RotatingFileHandler
但是,请看一下这个例子:
How to log everything into a file using RotatingFileHandler by using logging.conf file?
您可能不需要创建自己的类来完成您想要的任务。