【发布时间】:2010-12-14 16:58:08
【问题描述】:
我在尝试登录我的 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:04,066 - 根 - 警告 - 3
2010-12-14 11:39:04,066 - 根 - 错误 - 4
2010-12-14 11:39:04,066 - 根 - 关键 - 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()
【问题讨论】: