-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (24 loc) · 758 Bytes
/
main.py
File metadata and controls
31 lines (24 loc) · 758 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
31
import sys
from analyzer import analyze_log
def main():
if len(sys.argv) < 2:
print("Usage: python main.py <logfile>")
sys.exit(1)
log_file = sys.argv[1]
stats = analyze_log(log_file)
report = []
report.append("--- Log Analysis Report ---")
report.append(f"INFO: {stats['INFO']}")
report.append(f"WARNING: {stats['WARNING']}")
report.append(f"ERROR: {stats['ERROR']}")
report.append("\nMost Frequent Errors:")
for err, count in stats["errors"].items():
report.append(f"{count}x - {err}")
# Print to terminal
for line in report:
print(line)
# Write to file
with open("report.txt", "w") as f:
f.write("\n".join(report))
if __name__ == "__main__":
main()