Files
fa26_cs425_.group-mp_.team-01/MP1/generate_log.py
T
2026-09-13 00:12:56 -05:00

47 lines
1.3 KiB
Python

import random
import sys
machine_num = int(sys.argv[1])
machine_log_file = f"machine.{machine_num}.test.log"
num_lines = int(sys.argv[2])
log_level = ["TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL", "AUDIT"]
log_messages = [
"User logged in successfully.",
"Database connection established.",
"File not found: config.yaml",
"Memory usage is high.",
"Disk space is running low.",
"Unauthorized access attempt detected.",
"Configuration file updated.",
"Service restarted successfully.",
"Network latency is above threshold.",
"Scheduled backup completed.",
"System update installed.",
]
open(machine_log_file, "w").close()
for i in range(num_lines):
#on all
if i == 0:
log_entry = f"[{machine_num}-{i}] [INFO] TEST_ALL\n"
#unique
elif i == 1:
log_entry = f"[{machine_num}-{i}] [DEBUG] TEST_UNIQUE\n"
#on some
elif i == 2 and machine_num in [1, 3, 5, 7, 9]:
log_entry = f"[{machine_num}-{i}] [ERROR] TEST_SOME\n"
elif 3 <= i < 13:
log_entry = f"[{machine_num}-{i}] [INFO] TEST_MEDIUM\n"
else:
log_entry = f"[{machine_num}-{i}] [{random.choice(log_level)}] {random.choice(log_messages)}\n"
with open(machine_log_file, "a") as f:
f.write(log_entry)