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