From 291266c79ff900f7faccb0061604136993c58e4e Mon Sep 17 00:00:00 2001 From: UltraQbik Date: Wed, 28 Aug 2024 20:18:07 +0300 Subject: Add log saving Theoretically, it should work :) --- main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 3c7a1fe..ae8f19a 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ """ The mighty silly webserver written in python for no good reason """ - +import os import ssl import time import socket @@ -19,11 +19,20 @@ from src.status_code import * _usocket = socket.socket | ssl.SSLSocket # logging +if not os.path.exists("logs"): + os.mkdir("logs") +if os.path.isfile("logs/latest.log"): + import gzip + from datetime import datetime + with open("logs/latest.log", "rb") as file: + with gzip.open(f"{datetime.now().strftime('%d-%m-%y %H-%M-%S')}.log.gz", "wb") as comp: + comp.writelines(file) + os.remove("logs/latest.log") logging.basicConfig( level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s", handlers=[ - logging.FileHandler("runtime.log"), + logging.FileHandler("logs/latest.log"), logging.StreamHandler() ] ) @@ -59,6 +68,7 @@ _parser.add_argument("-v", "--verbose", action="store_true") ARGS = _parser.parse_args() + class HTTPServer: """ The mightier HTTP server! -- cgit 1.4.1