-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (39 loc) · 1.22 KB
/
main.py
File metadata and controls
49 lines (39 loc) · 1.22 KB
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
'''
Main python script that runs everything together
'''
from parser import parse_line, detect_format
from analyzer import LogAnalyzer
import os
def main():
clear = lambda: os.system('cls')
clear()
print("\n🧾 Log Parser 📢")
print("Diagnostic tool for finding errors, warnings, ")
print("and information from different types of Logfiles.\n")
logName = input("Name of file: ")
print("\n⏳ Parsing lines..")
with open(logName) as f:
lines = f.readlines()
log_format = detect_format(lines[:50])
if log_format == "app_log":
log_format = "Application"
elif log_format == "sys_log":
log_format = "Sys"
elif log_format == "web_server":
log_format = "Webserver"
else:
log_format = "❌ No log format detected."
print(f"🔎 Detected logfile type: {log_format}")
print("⏳ Analyzing lines...")
analyzer = LogAnalyzer()
for line in lines:
unknown_lines = 0
parsed = parse_line(line)
if parsed:
analyzer.process(parsed)
else:
unknown_lines += 1
print(analyzer.summary())
print(f"❓ Unknown lines: {unknown_lines}")
if __name__ == "__main__":
main()