《浅析python实现log日志文件加工初步源代码之1》《浅析python实现log日志文件加工初步源代码之3》import os,sys,string
def format_string(key,str):
return converted_string_lists[key][0](key, str)
def parse_string(str):
for key in converted_string_lists.keys():
if key in str:
return format_string(key, str)
return str
def translate_step0(str, lineno):
if ']' not in str:
return
index = str.index(']')
str = str[index+2:]
for subs in filter_subs:
if subs in str:
return
print "%d: %s" % (lineno, parse_string(str)),
def printfile(filename):
fd = file(filename)
lineno = 1
while 1:
try:
text = fd.next()
except:
break
translate_step0(text, lineno)
lineno = lineno + 1
fd.close()
def process_sdio_ireg(key, str):
# return ':'.join(converted_string_lists[key][1:])+'\n'
print string.atoi(str[str.index(' = ')+3:], 16)
return str
def process_sbi_interrupt(key, str):
# return ':'.join(converted_string_lists[key][1:])+'\n'
return str
def process_event(key, str):
return ':'.join(converted_string_lists[key][1:])+'\n'
return str
filter_subs = [
'Enter:',
'Leave:',
'Micco:',
'main-thread',
'sbi_write_ioreg()',
'sbi_read_ioreg()',
]
converted_string_lists = {
'sdio_ireg = ':[process_sdio_ireg, 'luther', 'v1.0'],
'sbi_interrupt: ':[process_sbi_interrupt, 'luther', 'v1.0'],
'EVENT: ':[process_event, 'luther', 'v1.0'],
}
if __name__ == "__main__":
if len(sys.argv) < 2:
print '\nError: please use command: wpr logfile.txt\n'
sys.exit()
for filename in sys.argv[1:]:
printfile(filename)
|
luther@gliethttp:~/python$ python wpr.py log.txt
4: sbi_interrupt: HOST_INT_STATUS_REG 0xa
7: luther:v1.0
10: sbi_write_ioreg() priv=c550a360 func=1 reg=0x3 dat=0x0
19: *
22: sbi_read_ioreg() priv=c550a360 func=1 reg=0x5 dat=0x1
24: sdio_ireg = 0x1
26: sbi_write_ioreg() priv=c550a360 func=1 reg=0x5 dat=0x2
29: sbi_read_ioreg() priv=c550a360 func=1 reg=0x42 dat=0x1
34: sbi_interrupt: HOST_INT_STATUS_REG 0x8
37: luther:v1.0
40: SLEEP_CFM:
41: 21 00 12 00 01 00 00 00 34 00 00 00 00 00 00 00
42: 00 00
51: *
54: sbi_read_ioreg() priv=c550a360 func=1 reg=0x5 dat=0x3
56: sdio_ireg = 0x3
58: sbi_write_ioreg() priv=c550a360 func=1 reg=0x5 dat=0x0
61: sbi_read_ioreg() priv=c550a360 func=1 reg=0x42 dat=0x1
66: sbi_interrupt: HOST_INT_STATUS_REG 0xa
68: *
71: sbi_read_ioreg() priv=c550a360 func=1 reg=0x5 dat=0x1
73: sdio_ireg = 0x1
75: sbi_write_ioreg() priv=c550a360 func=1 reg=0x5 dat=0x2
78: sbi_read_ioreg() priv=c550a360 func=1 reg=0x42 dat=0x1
83: sbi_interrupt: HOST_INT_STATUS_REG 0x8
86: luther:v1.0
89: SLEEP_CFM:
90: 21 00 12 00 01 00 00 00 34 00 00 00 00 00 00 00
91: 00 00
99: *
......
2263: luther:v1.0
2266: SLEEP_CFM:
2267: 21 00 12 00 01 00 00 00 34 00 00 00 00 00 00 00
2268: 00 00
2276: *
2280: sbi_read_ioreg() priv=c550a360 func=1 reg=0x5 dat=0x3
2282: sdio_ireg = 0x3
2284: sbi_write_ioreg() priv=c550a360 func=1 reg=0x5 dat=0x0
2287: sbi_read_ioreg() priv=c550a360 func=1 reg=0x42 dat=0x1
2292: sbi_interrupt: HOST_INT_STATUS_REG 0xa
2294: *
2297: sbi_read_ioreg() priv=c550a360 func=1 reg=0x5 dat=0x1
2299: sdio_ireg = 0x1
2301: sbi_write_ioreg() priv=c550a360 func=1 reg=0x5 dat=0x2
2304: sbi_read_ioreg() priv=c550a360 func=1 reg=0x42 dat=0x1
2309: luther:v1.0
2313: sbi_interrupt: HOST_INT_STATUS_REG 0x8
2315: sbi_write_ioreg() priv=c550a360 func=1 reg=0x3 dat=0x0
2324: luther:v1.0
阅读(1815) | 评论(0) | 转发(0) |