49 lines
1.3 MiB
Plaintext
Raw Normal View History

2026-01-29 06:54:10 +01:00
TASK: Create a dummy log file with 20 lines of mixed INFO and ERROR messages. Parse it using Python to count errors and save a JSON summary to 'log_analysis.json'.
----------------------------------------
Loading...
2026-01-29 08:06:31 +01:00
-> Reading file: dummy_log.txt
-> Writing file: dummy_log.txt
  CHANGES: dummy_log.txt 
LINE OLD
--------------------------------------------------------------------------------------------------------------------------------------------
1 ERROR message 0
2 INFO message 1
3 INFO message 2
4 ERROR message 3
5 INFO message 4
6 INFO message 5
7 ERROR message 6
8 INFO message 7
9 INFO message 8
10 ERROR message 9
11 INFO message 10
12 INFO message 11
13 ERROR message 12
14 INFO message 13
15 INFO message 14
16 ERROR message 15
17 INFO message 16
18 INFO message 17
19 ERROR message 18
20 INFO message 19
2026-01-29 07:42:06 +01:00
┌─── Python Source Code ─────────────────────────────────────
│  1 | import json
2026-01-29 08:06:31 +01:00
│  2 | # Read the log file
│  3 | with open('dummy_log.txt', 'r') as file:
│  4 | lines = file.readlines()
│  5 | # Count errors
│  6 | error_count = sum(1 for line in lines if 'ERROR' in line)
│  7 | # Create summary
│  8 | summary = {
│  9 | 'error_count': error_count,
│  10 | 'total_lines': len(lines)
│  11 | }
│  12 | # Save JSON summary
│  13 | with open('log_analysis.json', 'w') as json_file:
│  14 | json.dump(summary, json_file)
2026-01-29 07:42:06 +01:00
└────────────────────────────────────────────────────────────
2026-01-29 08:06:31 +01:00
A log file with 20 mixed INFO and ERROR messages has been created, and a JSON summary counting the errors has been saved to 'log_analysis.json'.