I have a need to watch a log document for changes. In the wake of glancing through intellipaat questions, I see individuals suggesting watchog. So I'm attempting to test, and I don't know where to add the code for when files change:
import time
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
if __name__ == "__main__":
event_handler = LoggingEventHandler()
observer = Observer()
observer.schedule(event_handler, path='.', recursive=False)
observer.start()
try:
while True:
time.sleep(1)
else:
print "got it"
except KeyboardInterrupt:
observer.stop()
observer.join()
Where do I actually add the "got it" — in the while loop if the records have been added/changed?