import os import time LOG_DIR = "logs" SECONDS_PER_DAY = 24 * 60 * 60 # folder, file name, size in KB, age in days test_files = [ ("", "backup.log", 12, 0), ("", "README.txt", 1, 90), ("nginx", "access.log", 850, 0), ("nginx", "access.log.1", 1200, 3), ("nginx", "access.log.2", 1100, 10), ("nginx", "access.log.3", 980, 45), ("nginx", "error.log", 40, 0), ("nginx", "error.log.1", 35, 12), ("app", "app.log", 300, 0), ("app", "app.log.1", 520, 20), ("app", "app.log.2", 610, 60), ("old", "legacy.log.1", 200, 120), ] for folder, name, size_kb, age_days in test_files: directory = os.path.join(LOG_DIR, folder) os.makedirs(directory, exist_ok=True) path = os.path.join(directory, name) with open(path, "w") as file: file.write("x" * size_kb * 1024) timestamp = time.time() - age_days * SECONDS_PER_DAY os.utime(path, (timestamp, timestamp)) print(f"Test logs created in {os.path.abspath(LOG_DIR)}")