Use the file pointer seek function to store the position f.tell() after each read into a file, and start reading from the new position in the next loop
with open('access.log') as f:
f.seek(n)
## processing
f.tell()
## save the newest postions to a file
A less relevant idea is that the system-level scheduled task cuts the nginx log at 0 o'clock every day and saves it by date. I have this script and it runs very stably. I can send it out when needed.
If it is a log, it should have a timestamp. Using SQLite for recording and querying is an option
There are 2 ways of thinking:
Use the file pointer seek function to store the position
f.tell()
after each read into a file, and start reading from the new position in the next loopA less relevant idea is that the system-level scheduled task cuts the nginx log at 0 o'clock every day and saves it by date. I have this script and it runs very stably. I can send it out when needed.