diff options
| author | UltraQbik <no1skill@yandex.ru> | 2024-08-28 20:18:07 +0300 |
|---|---|---|
| committer | UltraQbik <no1skill@yandex.ru> | 2024-08-28 20:18:07 +0300 |
| commit | 291266c79ff900f7faccb0061604136993c58e4e (patch) | |
| tree | 2400afefa4da344e98320ca917739d94e8722342 | |
| parent | 53037c46565a3a29f387561223ed4e360f34b759 (diff) | |
| download | httpy-291266c79ff900f7faccb0061604136993c58e4e.tar.gz httpy-291266c79ff900f7faccb0061604136993c58e4e.zip | |
Add log saving
Theoretically, it should work :)
| -rw-r--r-- | main.py | 14 |
1 files 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! |