about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUltraQbik <no1skill@yandex.ru>2024-08-27 03:58:24 +0300
committerUltraQbik <no1skill@yandex.ru>2024-08-27 03:58:24 +0300
commit3263cfdee15391995532545df84b8e4144684879 (patch)
tree2907c22ba62fca1693262a6c59407dcf3ec6c634
parent57c088390fa2444e7463dbfc10dc27c2f2b904be (diff)
downloadhttpy-3263cfdee15391995532545df84b8e4144684879.tar.gz
httpy-3263cfdee15391995532545df84b8e4144684879.zip
Add logging
-rw-r--r--main.py16
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