可能是java和lua的基础,这门语言学起来莫名的快,安装环境看了半天基础语法就开始写脚本了。
提取log日志文件夹的日志,error错误日志和add数据信息,定时更新当前日期的最新日志信息
需求还需要定时更新查找当天日志文件,后面补上
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os,sys,io,importlib
sys.setrecursionlimit(10000000)
importlib.reload(sys)
final = []
#work为绝对路径,windos下"d:/ProgramH5Server/H5_server_lj/log"
#linux运行1:chmod a+x log.py 2:sed -i 's/\r$//' log.py 3:./log.py
work = "d:/ProgramH5Server/H5_server_lj/log"
for root,dirs,files in os.walk(work):
for file in files:
final.append(os.path.join(root,file))
def writeline(file):
filename = file
log_dir = os.path.join(work, filename)
with io.open(log_dir, 'r', encoding='utf-8') as f:
print(file)
lines = f.readlines()
error_line = []
operate_line = []
for line in lines:
if 'Error' in line or 'ERROR' in line or 'Exception' in line or 'EXCEPTION' in line or './' in line :
error_line.append(line)
elif '---add' in line :
operate_line.append(line)
errorlogname = 'error.log'
operatelogname = 'operate.log'
resultwork = os.path.dirname(__file__)
log_a = os.path.join(resultwork, errorlogname)
log_b = os.path.join(resultwork, operatelogname)
with io.open(log_a, 'a',encoding='utf-8') as result:
result.write('日志文件错误:'+ file)
for i in list(set(error_line)):
result.write(i)
with open(log_b, 'a', encoding='utf-8') as result:
result.write('日志文件操作:'+ file)
for i in list(set(operate_line)):
result.write(i)
for file in final:
writeline(file)
#定时
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有