Python看门狗不记录文件系统事件

时间:2013-11-26 10:53:20

标签: python python-2.7 watchdog

我使用监视程序库编写了以下代码来监视文件系统:

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from watchdog.events import LoggingEventHandler
from multiprocessing import Process
from pydispatch import dispatcher
import logging


class Watchman(object):
    def __init__(self, path):
        self.path = path

    def start_watching(self):
        self.p = WatchDNSTask(self.path)
        self.p.start()

    def stop_watching(self):
        self.p.terminate()


class WatchDNSTask(Process):
    def __init__(self, path):
        Process.__init__(self)
        self.path = path
        self.event_handler = LoggingEventHandler()
        self.observer = Observer()
        self.observer.schedule(self.event_handler, path=path, recursive=False)

    def run(self):
        logging.info("Started monitoring {path}".format(path=self.path))
        self.observer.start()
        self.observer.join()
        logging.info("Stopped monitoring {path}".format(path=self.path))

但它不会记录任何东西。我已经坚持了很长一段时间,我错过了什么?

1 个答案:

答案 0 :(得分:0)

您需要配置日志记录。默认级别为WARNING

logging.basicConfig(level=logging.INFO)