手机上抓的log太大,文本编辑器的Find只能过滤出tag,按value过滤比较麻烦, 于是写了个python脚本, 几十万行的log, 很快就按指定条件过滤出来。 而且脚本很容易理解和修改。 PS: 不太完善, 编码要处理, 只能读取utf-8文件。 #遍历log文件,按指定TAG查找,并过滤指定的value,将value存入到result.txt中。 #2013年11月4日 import os import time import json FILE_NAME = 'logvv_gd11.txt' KEY = 'lost' TAG = 'onVideoStatus' size = os.path.getsize(FILE_NAME) / 1024 / 1024 if 10 < size : print("File too large , it will be take more time for to done. \n") def fetch(): fp = open(FILE_NAME) fp_res = open("lost.txt","w") str1 = 'info' str2 = '}' count =0 msg = 'All lost packages :' file_info = 'Work directory:'+os.getcwd()+' , File size:'+str(size)+'M\n' fp_res.write(file_info) total_lost = 0 losttime = time.time() for line in fp: #过滤 if line.find(TAG) ==-1: continue if len(line) < 20: continue #匹配 i1 = line.index(str1) +5 i2 = line.index(str2) +1 info = line[i1:i2] if len(info) < 1: continue json.dumps(info) decodejson = json.loads( info) lost = decodejson['lost'] if lost>0 : #输出 print(info) #保存 fp_res.write(line+'') count +=1 total_lost+=lost msg = msg+str(count) print(msg) fp_res.write(msg) losttime = (time.time() - losttime) print('Losttime:',losttime) print('Total lost packages:',str(total_lost)) fp_res.write(', Losttime:'+str(losttime)) fp.close() fp_res.close() fetch()
第1个python脚本:过滤webrtc log
猜你喜欢
转载自chenpeilei2003.iteye.com/blog/1971195
今日推荐
周排行