diff options
| author | UltraQbik <no1skill@yandex.ru> | 2024-08-27 03:58:24 +0300 |
|---|---|---|
| committer | UltraQbik <no1skill@yandex.ru> | 2024-08-27 03:58:24 +0300 |
| commit | 3263cfdee15391995532545df84b8e4144684879 (patch) | |
| tree | 2907c22ba62fca1693262a6c59407dcf3ec6c634 /main.py | |
| parent | 57c088390fa2444e7463dbfc10dc27c2f2b904be (diff) | |
| download | httpy-3263cfdee15391995532545df84b8e4144684879.tar.gz httpy-3263cfdee15391995532545df84b8e4144684879.zip | |
Add logging
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/main.py b/main.py index 93709f6..9098210 100644 --- a/main.py +++ b/main.py @@ -7,9 +7,9 @@ import ssl import time import socket import signal +import logging import threading import traceback - from src import APIv1 from src.config import * from src.request import * @@ -20,6 +20,9 @@ from src.file_man import PATH_MAP # typing usocket = socket.socket | ssl.SSLSocket +# logging +logging.basicConfig(filename="runtime.log", encoding="utf-8", level=logging.INFO) + class HTTPServer: """ @@ -114,9 +117,9 @@ class HTTPServer: except ssl.SSLEOFError: pass except OSError as e: - print(f"Request dropped due to: {e}") + logging.info(f"request dropped due to: {e}") except Exception: - print("Ignoring exception:\n", traceback.format_exc()) + logging.warning(f"ignoring exception:\n{traceback.format_exc()}") # Remove self from thread list and close the connection self.client_threads.remove(threading.current_thread()) @@ -216,8 +219,11 @@ class HTTPServer: time.sleep(0.005) except ssl.SSLEOFError: break - except OSError: - print(f"Client dropped due to: {traceback.format_exc()}") + except OSError as e: + logging.info(f"Client dropped due to: {e}") + break + except Exception: + logging.warning(f"ignoring exception:\n{traceback.format_exc()}") break return None |