This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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...
┌─── Python Source Code ─────────────────────────────────────
│  1 | import json
│  2 | # Create dummy log file
│  3 | log_lines = [f"INFO: Message {i}" if i % 2 == 0 else f"ERROR: Message {i}" for i in range(20)]
│  4 | with open('dummy_log.txt', 'w') as f:
│  5 | f.write('\n'.join(log_lines))
│  6 | # Parse log file to count errors
│  7 | error_count = 0
│  8 | with open('dummy_log.txt', 'r') as f:
│  9 | for line in f:
│  10 | if line.startswith('ERROR'):
│  11 | error_count += 1
│  12 | # Create JSON summary
│  13 | summary = {
│  14 | "total_lines": 20,
│  15 | "error_count": error_count
│  16 | }
│  17 | # Save summary to JSON file
│  18 | with open('log_analysis.json', 'w') as f:
│  19 | json.dump(summary, f)
└────────────────────────────────────────────────────────────
A dummy log file with 20 lines of mixed INFO and ERROR messages has been created. The script parsed the log to count the errors and saved the summary as JSON in 'log_analysis.json'.