如何读取并采集动态增长的日志文件

来源:互联网 发布:坚果s1安装软件 编辑:程序博客网 时间:2024/05/16 01:18

想抓取一个Linux应用的日志文件,采集里面的有用信息。但由于日志文件是动态增长的,且增长相对较快,有没有什么好的方法只抓取最新的内容。

抄自 David M. Beazley:

import timedef follow(thefile):     thefile.seek(,2)    while True:        line = thefile.readline()        if not line:            time.sleep(0.1)            continue         yield line
原创粉丝点击