Python截取Tomcat错误日志详解

版权声明:所有文章都是自己原创,谢谢。 https://blog.csdn.net/weixin_42840933/article/details/85097609
import re
import os
def error(logname):
    f1=open(logname,encoding='utf-8')#encoding='gbk'
    my=[]
    for a in f1:
        b=re.search('error',a,re.IGNORECASE)
        c=re.search('exception',a,re.IGNORECASE)
        d=re.search('at java',a,re.IGNORECASE)
        e=re.search('at com',a,re.IGNORECASE)
        f=re.search('at org',a,re.IGNORECASE)
        g=re.search('at sun',a,re.IGNORECASE)
        if b or c or d or e or f or g:
            log_str=a
            my.append(log_str)
    errlog='C:\\Users\\user\\Desktop\\error.log'
    f2=open(errlog,'w')
    f2.writelines(my)
    f2.flush()
    f2.close()
    f1.close()
    return 0

error('C:\\Users\\user\\Desktop\\11.txt')

猜你喜欢

转载自blog.csdn.net/weixin_42840933/article/details/85097609