q987654 发表于 2017-5-4 12:44:29

Python实战1-解析日志模块

  根据用户提供的分隔符,分解日志数据
  该模块作用有2个:
  1)提前检测能否正确解析日志,否则用户需要修改分隔符,或者日志格式
  2)准备导入数据库的数据

logparse.py
def parselogline(line, tupleseperatorlist):
'''
input
line: line in log file
tupleseperatorlist: seperators in tuple
output
splited values
'''
data = []
for tupleseperator in tupleseperatorlist:
head = tupleseperator
end = tupleseperator
if not head :
endindex = line.find(end)
value = line
elif not end:
headindex = line.find(head)
value = line
else :
headindex = line.find(head)
endindex = line.find(end)
value = line
data.append(value)
return data
页: [1]
查看完整版本: Python实战1-解析日志模块