This repository has been archived by the owner on Feb 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcLog.py
78 lines (40 loc) · 1.76 KB
/
pcLog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Python Script to parse logs
import re
import csv
log_file_path = r"C:\Users\smarshall\Desktop\python\logs\pclog.log"
# regex = '(<property name="(.*?)">(.*?)<\/property>)'
## Regexs ##
date = '([0-9]{4}-[0-9]{2}-[0-9]{2}(?=\s\d{1,2}))'
time = '([\d]{1,2}:[\d]{1,2}:[\d]{1,2}.[\d]{1,3})'
datetime = '([0-9]{4}-[0-9]{2}-[0-9]{2})\s([\d]{1,2}:[\d]{1,2}:[\d]{1,2},\d{1,3})'
timefraction = r'(,\d{1,3})'
workqueue = r'(\bWorkqueue\sDWM\W\sSending\smessage\W\sWorkflow\b)'
regexs = [datetime,timefraction,workqueue]
# List for columns.......
match_list=[[]]
headers = "datetime,txn"
def readwrite(i):
with open(log_file_path, "r") as file:
with open(r'C:\Users\smarshall\Desktop\python\splitlog.csv', 'w') as outfile:
outfile.write(headers + "\n")
### For line in the log file match up the regex and chuck it in a list... then write a row
for line in file:
for r in regexs:
for match in re.finditer(r, line, re.S):
match_text = match.group()
if match is not None:
match_list[i].append(match_text)
row =str(match_list[i]).replace("'","")
commaCount = row.count(',')
if commaCount > len(regexs)-1:
outfile.write(row.strip("[]") +"\n")
i += 1
match_list.append([])
def writerows():
for item in match_list:
with open(r'C:\Users\smarshall\Desktop\python\splitlog.csv', 'w') as outfile:
columnhead = ["date", "time"]
# writer=csv.DictWriter(outfile,fieldnames=columnhead)
outfile.write(item+"\n")
readwrite(0)
# You have a csv file with some columns and some data...