As a simple application python, where the error log file contents oracle interception.
The concept of the: After analysis log results, timestamp as wedges, content as a block between the two time stamps, the memory block error Ruoguo content, will block content between two time stamps printed.
1 import re 2 3 def get_time(week,tmp_file): 4 time = [] 5 for line in tmp_file: 6 tmp_line = line.split() 7 lens = len(tmp_line) 8 #print(lens) 9 if lens > 3 : 10 if (tmp_line[0] in week[:]) and (int(tmp_line[2]) in range(1,32)): 11 time.append(line.strip()) 12 return time 13 14 def get_logs(time,filetxt): 15 i= 0 16 n = i+1 17 while i < len(time)-1 : 18 while time[i] == time[n]: 19 n +=1 20 if n == len(time)-1: 21 break 22 pattern = re.compile( time[i]+'(.*?)'+time[n],re.S) 23 result = re.findall(pattern,filetxt) 24 seltxt = result[0] 25 if " ORA- " in seltxt or " the Errors " in seltxt or " error " in seltxt or " TNS- " in seltxt: 26 is Print ( ' \ n-\ === >> n-given starting time: ' , Time [I] ) 27 Print ( '' .join (Result)) 28 # Print (type (Result)) 29 Print ( ' << === termination given start time: ' , time[n]) 30 i = n 31 32 def main(): 33 logfile = r'D:\WorkHome\python\oracle\alert_irmsdb.log' 34 week = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] 35 file = open(logfile) 36 filelines = file.readlines() 37 tmp_file = filelines[-200:] 38 time = get_time(week,tmp_file) 39 filetxt = "".join(tmp_file).strip() 40 get_logs(time,filetxt) 41 42 if __name__ == '__main__': 43 main()