import subprocess
import time
-from line import Line
-
MAX_LINES = 10
ALERT_INTERVAL = 86400
-def follow(filename):
+def follow(path):
while True:
try:
- with open(filename, "r") as f:
+ fd = os.open(path, os.O_RDONLY)
+ current_ino = os.fstat(fd).st_ino
+ with os.fdopen(fd, "r") as f:
logging.info("Re-attached to log file.")
for line in f: pass
while True:
line = f.readline()
if not line:
- if not os.path.exists(filename):
+ if os.stat(path).st_ino != current_ino or \
+ os.stat(path).st_size < f.tell():
break
else:
time.sleep(1.0)
if error_state:
logging.info("Leaving error state.")
error_state = False
- feed_handler( create_msg("Log Un-Alert",
- "🌞",
- args.logfile,
- "Log is back to normal.",
- lines) )