- 论坛徽章:
- 5
|
本帖最后由 Linux_manne 于 2014-11-18 11:14 编辑
思路差不多这样吧:
打开log文件 同时记录st_mtime 和seek 到文件末 记录 tell ,然后等待 st_mtime 发生变化即大于上一个st_mtime (该文件就发生了变化) 然后find 你得关键字
- line_num = 0
- end = 0
- initial = getnewlog(path,logob)
- while True:
- newest = getnewlog(path,logob)
- if newest != initial:
- line_num = 0
- end = 0
- initial = newest
- with open(newest) as f:
- current = os.stat(newest).st_mtime
- if current > end:
- end = current
- f.seek(line_num,0)
- content = f.readlines()
- f.seek(0,2)
- line_num = f.tell()
- for c in content:
- if c.find(pattern_key) != -1: # 这边弄自己的
- # 处理你得统计什么得
复制代码 |
|