我似乎在尝试将日志记录到我的python项目时遇到了一些问题。Python日志记录配置文件
我只是试图模仿如下配置:
Python Logging to Multiple Destinations
然而,而不是做这个的代码里面,我想有它的配置文件。
下面是我的配置文件:
[loggers]
keys=root
[logger_root]
handlers=screen,file
[formatters]
keys=simple,complex
[formatter_simple]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
[formatter_complex]
format=%(asctime)s - %(name)s - %(levelname)s - %(module)s : %(lineno)d - %(message)s
[handlers]
keys=file,screen
[handler_file]
class=handlers.TimedRotatingFileHandler
interval=midnight
backupCount=5
formatter=complex
level=DEBUG
args=('logs/testSuite.log',)
[handler_screen]
class=StreamHandler
formatter=simple
level=INFO
args=(sys.stdout,)
的问题是,我的屏幕输出如下:
2010-12-14 11:39:04066 - 根 - 警告 - 3
2010-12 -14 11:39:04066 - 根 - 错误 - 4
2010-12-14 11:39:04066 - 根 - CRITICAL - 5
我的文件被输出,但与看起来与上述相同的(尽管包括额外信息)。但是,调试和信息级别不会输出到任何一个。
我对Python的2.7
这里是我的简单的例子显示故障:
import os
import sys
import logging
import logging.config
sys.path.append(os.path.realpath("shared/"))
sys.path.append(os.path.realpath("tests/"))
class Main(object):
@staticmethod
def main():
logging.config.fileConfig("logging.conf")
logging.debug("1")
logging.info("2")
logging.warn("3")
logging.error("4")
logging.critical("5")
if __name__ == "__main__":
Main.main()