logging.handlers.WatchedFileHandler不起作用

2024-10-06 14:19:25 发布

您现在位置:Python中文网/ 问答频道 /正文

以下代码以前对我有效,应该根据文档工作:

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging.handlers
>>> logging.handlers.WatchedFileHandler("log.log")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'WatchedFileHandler'

从文件中:

^{pr2}$

这可能是什么原因?在


Tags: 代码文档logdefaultonlogginghandlerstype
2条回答

如果有人在使用python3时遇到了相同的问题,可以通过如下方式分别导入logging.handlers和{}来解决

import logging.handlers
logging.handlers.WatchedFileHandler('example.log')

日志记录是由pipeasy_install手动安装的,但是pip中的包比较旧,因此我在/usr/local/lib/python2.7/dist-packages中安装了0.4.9.6版本,而最新的版本是在usr/lib/python2.7中随python一起安装的。在服务器上,dist-package似乎位于路径的前面,但不在桌面上。无论如何,删除旧的包解决了这个问题。在

相关问题 更多 >