我想我错过了一些重要的东西,对于我的生活,我无法弄清楚。我有一个logging.conf
文件,我正在尝试xyz.py
读取我的主要(比如 )文件。但我收到了这个奇怪的错误。我有下面的回溯,然后是配置文件 -logging.conf
然后是xyz.py
.
File "xyz.py", line 28, in <module>
log = logging.config.fileConfig('/Users/Username/Desktop/logging.conf')
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 78, in fileConfig
handlers = _install_handlers(cp, formatters)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 156, in _install_handlers
h = klass(*args)
TypeError: __init__() takes at most 7 arguments (23 given)
配置文件 - 完整路径 = /Users/Username/Desktop/logging.config
(我按照http://docs.python.org/release/2.5.2/lib/logging-config-fileformat.html的说明进行操作)
[loggers]
keys=root
[handlers]
keys=handlersmtp, handlerfile
[formatters]
keys=formatter
[formatter_formatter]
format=%(asctime)s %(name)s %(levelname)s %(message)s
datefmt=
class=logging.Formatter
[logger_root]
level=NOTSET
handlers=handlersmtp, handlerfile
[handler_handlersmtp]
class=handlers.SMTPHandler
level= INFO
formatter=formatter
args=(('localhost', 25),'localhost@localhost.com', ['abc@bca.com'],
'The log')
[handler_handlerfile]
class=handlers.RotatingFileHandler
level= INFO
formatter=formatter
backupCount=1440
args=('alogger.log')
主文件中的部分 -xyz.py
import logging
import logging.config
log = logging.config.fileConfig('/Users/Username/Desktop/logging.config')
我查看了 Python is logging/config.py 模块,但无法理解它为什么会提出这个问题。这是一个相当大的文件。
编辑:
@VineySajip 的回答删除了上面的错误,但我现在正在处理这个新错误。
[handler_handlerfile]
class=handlers.RotatingFileHandler
level= INFO
formatter=formatter
args=('alogger.log', mode='a', maxBytes=25000,
backupCount=0, encoding=None, delay=0) #New line to fit
#this page but code has it all in 1 line
新的追溯:
Traceback (most recent call last):
File "cpu6.py", line 29, in <module>
log = logging.config.fileConfig('/Users/Username/Desktop/logging.ini')
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/
Versions/2.7/lib/python2.7/logging/config.py", line 78, in fileConfig
handlers = _install_handlers(cp, formatters)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/
Versions/2.7/lib/python2.7/logging/config.py", line 155, in _install_handlers
args = eval(args, vars(logging))
File "<string>", line 1
('alogger.log', mode='a', maxBytes=25000,
backupCount=0, encoding=None, delay=0)
^
SyntaxError: invalid syntax