我已经为我的django站点实现了我自己的自定义记录器:
class SpecialLogger(logging.Logger):
def __init__(self, name, level=logging.DEBUG):
logging.Logger.__init__(self, name, level)
def special(self, msg, *args, **kwargs):
self.log(self.level, msg, *args, **kwargs)
在我的wsgi文件中,我添加了以下行:
^{pr2}$在我的django看来:
1 import logging
2 logger = logging.getLogger('mylog')
3 print str(logging.getLoggerClass())
4 print str(logger)
5 print dir(logger)
第三行打印testbed.utils.SpecialLogger
第4行打印<logging.Logger instance at 0x21aadcac>
第5行(当然)没有显示我的函数special
我做错了什么?为什么第3行和第4行之间存在差异?在
setLoggerClass函数设置在调用返回后实例化的所有记录器所使用的类,但在调用之前创建的任何记录器仍将日志记录。记录器. 您可以在wsgi文件中附加一行来确认使用的类是正确的,例如
如果这不能产生所需的效果,那么在运行上述代码之前,其他一些代码(例如,
settings.py
)必须实例化记录器。在相关问题 更多 >
编程相关推荐