利用Python提取log有用信息并写入excel

本文介绍如何使用Python从log日志中提取关键信息,并将这些信息整理写入Excel表格,以便进行更直观的数据分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于log日志比较记录的事件比较多,很难直观分析自己想要的数据信息,因此就想把log中的有用信息提取出来,便于分析:

#coding=utf-8
import re
import os
import time
import xlwt
import datetime

path = r'C:\Users\qxrxxxx\Desktop\log'

downloadtime = time.strftime('%Y_%m_%d')
filename = 'NotificationTest_' + downloadtime + '.xls'
workbook = xlwt.Workbook(encoding='ascii')
worksheet = workbook.add_sheet('Comment')
workbook.save(filename)

font = xlwt.Font()  # Create the Font
font.bold = True
font.colour_index = 1
font.height = 0x00C8  # C8 in Hex (in decimal) = 10 points in height.
style = xlwt.XFStyle()  # Create the Style
style.font = font  # Apply the Font to the Style
pattern = xlwt.Pattern()  # Create the Pattern
pattern.pattern = xlwt.Pattern.SOLID_PATTERN  # May be: NO_PATTERN, SOLID_PATTERN, or 0x00 through 0x12
pattern.pattern_fore_colour = 23  # May be: 8 through 63. 0 = Black, 1 = White, 2 = Red, 3 = Green, 4 = Blue, 5 = Yellow, 6 = Magenta, 7 = Cyan, 16 = Maroon, 17 = Dark Green, 18 = Dark Blue, 19 = Dark Yellow , a
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值