about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUltraQbik <no1skill@yandex.ru>2024-08-28 20:24:15 +0300
committerUltraQbik <no1skill@yandex.ru>2024-08-28 20:24:15 +0300
commitc99d4f8a565de44793930d9f9d142e4a79c061ca (patch)
tree9e7583119394769308209f68c34eedc56fc7a7c9
parent291266c79ff900f7faccb0061604136993c58e4e (diff)
downloadhttpy-c99d4f8a565de44793930d9f9d142e4a79c061ca.tar.gz
httpy-c99d4f8a565de44793930d9f9d142e4a79c061ca.zip
Fixed logging and added LOGGER_PATH into config.py
-rw-r--r--.gitignore1
-rw-r--r--main.py14
-rw-r--r--src/config.py1
3 files changed, 9 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 30a88c1..93547eb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -167,3 +167,4 @@ cython_debug/
 /compress/
 /fullchain.pem
 /privkey.pem
+/logs/
diff --git a/main.py b/main.py
index ae8f19a..3a14ff2 100644
--- a/main.py
+++ b/main.py
@@ -19,20 +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"):
+if not os.path.exists(f"{LOGGER_PATH}"):
+    os.makedirs(f"{LOGGER_PATH}")
+if os.path.isfile(f"{LOGGER_PATH}/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:
+    with open(f"{LOGGER_PATH}/latest.log", "rb") as file:
+        with gzip.open(f"{LOGGER_PATH}/{datetime.now().strftime('%d-%m-%y %H-%M-%S')}.log.gz", "wb") as comp:
             comp.writelines(file)
-    os.remove("logs/latest.log")
+    os.remove(f"{LOGGER_PATH}/latest.log")
 logging.basicConfig(
     level=logging.INFO,
     format="%(asctime)s [%(levelname)s] %(message)s",
     handlers=[
-        logging.FileHandler("logs/latest.log"),
+        logging.FileHandler(f"{LOGGER_PATH}/latest.log"),
         logging.StreamHandler()
     ]
 )
diff --git a/src/config.py b/src/config.py
index fe28e6d..29b18e3 100644
--- a/src/config.py
+++ b/src/config.py
@@ -1,4 +1,5 @@
 # generic
+LOGGER_PATH = "logs"
 BUFFER_LENGTH = 65536           # 64 KiB
 BUFFER_MAX_SIZE = 2**30 * 0.5   # 512 MiB
 CLIENT_MAX_AMOUNT = 512         # max requests at once, after which the connections are dropped