You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
347 B
15 lines
347 B
import os
|
|
import time
|
|
|
|
LOG_FILE = "logs/app.log"
|
|
MAX_SIZE_MB = 50 # rotate if too big
|
|
|
|
def cleanup_logs():
|
|
if not os.path.exists(LOG_FILE):
|
|
return
|
|
|
|
size_mb = os.path.getsize(LOG_FILE) / (1024 * 1024)
|
|
|
|
if size_mb > MAX_SIZE_MB:
|
|
os.rename(LOG_FILE, f"logs/app_{int(time.time())}.log")
|
|
open(LOG_FILE, "w").close() |