python buildlog 实例

import re

warninglist = []
warninglist.append("warning cd{4}")

errorlist = []
errorlist.append("error lnkd{4}")
errorlist.append("error cd{4}")

def parse(logfile, regexlist):
resultlines = []
with open(logfile, "r") as log:
for line in log:
for regex in regexlist:
m = re.search(regex, line)
if m:
resultlines.append(line)
return resultlines

def parsewarning(logfile):
warnings = []
warnings = parse(logfile, warninglist)
return warnings

def parseerror(logfile):
errors = []
errors = parse(logfile, errorlist)
return errors

ws = parsewarning("buildlog.txt")
print( "warnings:" + str(len(ws)))
for w in ws:
print (w)
es = parseerror("buildlog.txt")
print( "errors:" + str(len(es)))
for e in es:
print(e)

简单地解析visualstudio的buildlog:(有的时候log文件太长,但是我们只是关心warning和error, 通过该程序可以直接得到所有的warning和error的行

分类:默认分类 时间:2015-03-13 人气:2
本文关键词:
分享到:

相关文章

Copyright (C) quwantang.com, All Rights Reserved.

趣玩堂 版权所有 京ICP备15002868号

processed in 0.043 (s). 10 q(s)