I have a log monitoring python script I'm working on. It sends messages when entries with the text "disconnected" are found. The script reads the log until it comes across a "End of log file" message. In its current state it sends the messages as they come across. This isn't optimal and I need to pool them for say 5 minutes before sending the collected entries. I am not sure what the best method for doing this is. Here is a simplified version of what I am trying to do. So far I’ve tried time.sleep and an elaborate incremental counter to no avail.
# Open log
f = open(log, 'r')
# Start while loop and read line
while(1):
# Check for Disconnected
if line.find("disconnected") != -1:
ltime = time.time()
print ("Disconnected Found in Log at " + ltime)
# Check for end of log file
if line.find("End of file") != -1:
# End script
break