根据用户提供的分隔符,分解日志数据
该模块作用有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[0] end = tupleseperator[1] if not head : endindex = line.find(end) value = line[0:endindex] elif not end: headindex = line.find(head) value = line[headindex + len(head) :] else : headindex = line.find(head) endindex = line.find(end) value = line[headindex + len(head): endindex] data.append(value) return data