Search code examples
pythontail

How can I tail a log file in Python?


I'd like to make the output of tail -F or something similar available to me in Python without blocking or locking. I've found some really old code to do that here, but I'm thinking there must be a better way or a library to do the same thing by now. Anyone know of one?

Ideally, I'd have something like tail.getNewData() that I could call every time I wanted more data.


Solution

  • So, this is coming quite late, but I ran into the same problem again, and there's a much better solution now. Just use pygtail:

    Pygtail reads log file lines that have not been read. It will even handle log files that have been rotated. Based on logcheck's logtail2 (http://logcheck.org)