-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_log.py
More file actions
30 lines (24 loc) · 762 Bytes
/
parse_log.py
File metadata and controls
30 lines (24 loc) · 762 Bytes
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
try:
from parse import parse
import os
import csv
except:
print("Haven't install the parse module ")
print("Please use 'pip install parse' install parse module ")
exit(0)
file_path = input("please input the log path")
if not os.path.isfile(file_path):
print("The file_path not currently, please check again")
exit(0)
f = open(file_path)
with open("parsed.csv", "w") as csvfile:
writer = csv.writer(csvfile)
logs = f.readlines()
for single_log in logs:
single_log = single_log.strip('\n')
result = parse("[{}] {} {} [{}] {} ({}) [{}][{}][{}][{}] [{}] {}", single_log)
if result:
writer.writerow([ele for ele in result])
else:
continue
print("Finish parse")