python脚本通过时间范围统计日志数

error.22
2023-10-28 21:06:58.646 - rpt-push request to http://10.xx.1xx.xx:8000/umpay/report error, http status = 501
2023-10-28 21:06:58.646 - rpt-push  发送请求异常:
com.umpay.typhos.kernel.fault.Fault: RequestException:向对方请求时发生除了通讯异常和请求超时的其它错误
    at com.umpay.typhos.kernel.fault.Err.makeFault(Err.java:52) ~[typhos-kernel-2.0.0-SNAPSHOT.jar:na]
    at com.umpay.mgr.web.pushreport.SendRunableUtil.sendSms(SendRunableUtil.java:78) [classes/:na]
    at com.umpay.mgr.web.pushreport.SendRunableUtil.run(SendRunableUtil.java:52) [classes/:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_11]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_11]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_11]
2023-10-28 21:06:58.737 - rpt-push  max retry time[3] RePushRptMsg  submitMsgId:1028193854001000105023 submitApReqId:1698496210   mobile:15261xxxx34 destId:15261056234 deliverd:true  status:DELIVRD submitTime:2023-10-28 19:38:55 doneTime:2023-10-28 19:38:55   gwId:  gwMsgId:   gwReqId:   mt_total:1 mt_success:1   mt_failure:0   dup:3
2023-10-28 21:06:58.737 - rpt-push  max retry time[3] RePushRptMsg  submitMsgId:1028193857001000105269 submitApReqId:1698496333   mobile:15261xxxx34 destId:15261056234 deliverd:true  status:DELIVRD submitTime:2023-10-28 19:38:57 doneTime:2023-10-28 19:39:02   gwId:  gwMsgId:   gwReqId:   mt_total:1 mt_success:1   mt_failure:0   dup:3
2023-10-28 21:06:58.737 - rpt-push 线程池已满,睡眠1000ms
2023-10-28 21:06:58.737 - rpt-push 线程池已满,睡眠1000ms
2023-10-28 21:06:59.449 - rpt-push request to http://10.xx.xx3.xx:8000/umpay/report error, http status = 501
2023-10-28 21:06:59.450 - rpt-push  发送请求异常:
com.umpay.typhos.kernel.fault.Fault: RequestException:向对方请求时发生除了通讯异常和请求超时的其它错误
    at com.umpay.typhos.kernel.fault.Err.makeFault(Err.java:52) ~[typhos-kernel-2.0.0-SNAPSHOT.jar:na]

# -*- coding: UTF-8 -*-

import time

# 日志文件名称
logfile = 'error.22'
def choose_log1():
    # 定义截取的时间范围
    start_time = time.strptime('2023-10-28 20:40:00',"%Y-%m-%d %H:%M:%S")
    end_time = time.strptime('2023-10-28 22:45:00',"%Y-%m-%d %H:%M:%S")
    i=0
    # 打开日志
    with open(logfile, 'r',encoding='utf-8') as logs:
        for line in logs:
            if "2023-10-28" in line[:19]:
                t = time.strptime(line[:19],"%Y-%m-%d %H:%M:%S")
                if t > end_time:
                    break
                if t > start_time:
                    if "max retry time[3]" in line:
                        print(line, end='')
                        i=i+1
    print("总数:"+str(i))

if __name__ == '__main__':
    choose_log1()

 

你可能感兴趣的:(python,开发语言)