fbence
fbence

Reputation: 2153

logging.handlers.WatchedFileHandler not working

The following code has worked for me before and should work according to documentation:

$ 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'

From the docs:

 class logging.handlers.WatchedFileHandler(filename[, mode[, encoding[, delay]]])

What could be the cause of this?

Upvotes: 0

Views: 900

Answers (2)

Greenev
Greenev

Reputation: 909

If somebody has faced with the same problem when using python3, it could be resolved by importing logging.handlers separately from logging like this

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

Upvotes: 1

fbence
fbence

Reputation: 2153

The logging was manually installed by pip or easy_install, but the packages in pip are older, thus I had version 0.4.9.6 installed in /usr/local/lib/python2.7/dist-packages while the more recent version was installed along python in usr/lib/python2.7. It seems on the server the dist-package was earlier in the path but not on the desktop. Anyhow, deleting the older package solved the issue.

Upvotes: 0

Related Questions