Louie NRT Story

[Raspberry Pi] Watchdog 본문

에너지

[Raspberry Pi] Watchdog

hyeok0724.kim@gmail.com 2019. 10. 28. 17:12
반응형

Writed on 28 OCT 2019
Device: Raspberry Pi 3
Raspbian Version: 2019-09-26-raspbian-buster-full.zip

1. Install Watchdog

2. Start service

 - This service shows create or modify log at this current directory.

 

3. Start programming

import sys
import time
import logging
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    path = sys.argv[1] if len(sys.argv) > 1 else '.'
    event_handler = LoggingEventHandler()
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()

 - This program shows create or modify log at this current directory.

 

Reference: https://github.com/gorakhargosh/watchdog

반응형
Comments