zoukankan      html  css  js  c++  java
  • python解析oracle日志中的报错

    作为python的简单应用,这里将oracle日志文件中的报错内容截取出来。

    方案构思:经过分析日志结果,以时间戳为楔子,两个时间戳之间内容作为分块,若果分块内存在报错内容,就将两个时间戳之间的分块内容打印出来。

     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 "Errors" in seltxt or "error" in seltxt or "TNS-" in seltxt:
    26             print('
    
    ===>>报错起始时间:', time[i])
    27             print(''.join(result))
    28             # print(type(result))
    29             print('<<===报错终止始时间:', time[n])
    30         i = n
    31 
    32 def main():
    33     logfile = r'D:WorkHomepythonoraclealert_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()
  • 相关阅读:
    自定义UILabel,使文字居左上显示
    xcode 7 运行项目报错 -fembed-bitcode is not supported on versions of iOS prior to 6.0
    git 如何删除本地未提交的文件
    coco2d-x技术
    mac 查看端口是否被使用
    ios 提交
    oc基础复习10-OC的id
    oc基础复习09-OC的self 和super(深入理解)
    oc基础复习08-OC的类方法
    oc基础复习07-OC的弱语法(转)
  • 原文地址:https://www.cnblogs.com/cooper-73/p/10965780.html
Copyright © 2011-2022 走看看