我为我的项目编写了一个记录器。我记录到文本文件,你可能会猜到有一个时间戳,命名空间,类,方法......最后是一条日志消息。像这样:
TestNamespace.MyProject.exe Error: 0 :
11/11/2010 10:24:11 AM
Assembly: TestNamespace.MyProject.exe
Class: myClass
Method: Test
This is a log message !
TestNamespace.MyProject.exe Error: 0 :
11/11/2010 10:24:12 AM
Assembly: TestNamespace.MyProject.exe
Class: myClass
Method: Test2
This is another log message !
我正在寻找一个免费工具来分析我的日志文件(一些表格,图表等)。 提前谢谢。
答案 0 :(得分:0)
由于您以自定义格式输出日志消息,因此您实际上需要一个自定义解析器。
答案 1 :(得分:0)
的Python
import datetime
from collections import namedtuple
Record = namedtuple( 'Record', 'file,level,number,datetime,assembly,class,method,message' )
def block_iter( theFile ):
file_iter= iter(theFile)
while True:
items= [ next(file_iter) for x in range(9) ]
if not items: break
yield items
def record_iter( blocks ):
for items in blocks:
file, level, number = items[0].split(":")
dt = datetime.datetime.strptime( items[1], "%m/%d/%Y %H:%M:%S %p" )
_, _, asm = items[2].partition(":")
_, _, cls = items[3].partition(":")
_, _, mth = items[4].partition(":")
txt = "".join( items[5:] )
yield Record( file, level, number, dt, asm, cls, mth, txt )
with open( "someapp.log", "r" ) as source:
for log in record_iter( block_iter( source ) ):
print log
这样的事情可能会帮助你入门。
答案 2 :(得分:0)
Microsoft有一个LogParser
,它对任何日志格式都非常灵活。缺点是,它是一个命令行工具,并没有从2005(版本2.2)的变化。您可以针对日志文件编写SQL命令,它将为您生成正确的表/图表。为它编写了一些GUI工具。