我已将 Python 的日志记录模块添加到我的代码中,以避免混乱的打印语句,但我却因配置错误而陷入困境。错误消息的信息不是很丰富。
Traceback (most recent call last):
File "HDAudioSync.py", line 19, in <module>
logging.config.fileConfig('../conf/logging.conf')
File "/usr/lib64/python2.6/logging/config.py", line 84, in fileConfig
handlers = _install_handlers(cp, formatters)
File "/usr/lib64/python2.6/logging/config.py", line 162, in _install_handlers
h = klass(*args)
TypeError: __init__() takes at most 5 arguments (21 given)
我的配置文件中没有提供 21 个参数。
这是配置文件
[loggers]
keys=root,main, sftp, jobapi
[handlers]
keys=console, logfile, syslog
[formatters]
keys=simple, timestamp
[logger_root]
level=NOTSET
handlers=logfile
[logger_main]
level=DEBUG
handlers=console, logfile, syslog
propagate=1
qualname=main
[logger_sftp]
level=DEBUG
handlers=console, logfile, syslog
propagate=1
qualname=sftp
[logger_jobapi]
level=DEBUG
handlers=console, logfile, syslog
propagate=1
qualname=jobapi
[handler_console]
class=StreamHandler
level=DEBUG
formatter=simple
args=(sys.stdout,)
[handler_logfile]
class=FileHandler
level=DEBUG
formatter=timestamp
args=('../log/audiosync.log')
[handler_syslog]
class=FileHandler
level=WARN
formatter=timestamp
args=('../log/audiosync.sys.log')
[formatter_simple]
format=%(levelname)s - %(message)s
[formatter_timestamp]
format=%(asctime)s - %(name)s -%(levelname)s - %(message)s
这是我的主模块中的日志记录初始化代码:
import logging
import logging.config
import logging.handlers
logging.config.fileConfig('../conf/logging.conf')
logger = logging.getLogger('main')
我并不是在寻找我在这里做错了什么(尽管这很好),而是在寻找一种调试方法。
Thanks.