I need to read a application log file dynamically and based on the newly added lines in the log, need to take some action for example, notify a service(call-back). I have no control on who writes to this log file. For now, reading the whole log file is also fine, since its an error log and gets updated very less often hence will not grow too much in a single uptime. In that case I can read the whole file(and find out the diff) whenever it is updated. If the solution comes from within python's core libs, it will be helpful.
Asked
Active
Viewed 206 times
0
-
1Does this answer your question? [How can I tail a log file in Python?](https://stackoverflow.com/questions/12523044/how-can-i-tail-a-log-file-in-python) – Vulpex Mar 05 '21 at 20:15
1 Answers
0
If the log file is only appended without any lines being deleted you can probably try to save the index of the last line.
If you later open the file again, you can start reading the lines from that index. As I can see, this is possible to do with readlines() or probably even better with linecache (which was mentioned later in the first link).

tpwo
- 484
- 3
- 12