From 34bdabc4db71b70e6b386d90f43a3be5610660eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=99=E5=AE=81=E5=A8=9C?= <3072252442@qq.com> Date: Sun, 17 Mar 2024 14:08:21 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20Log4p/websocketHander.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Log4p/websocketHander.py | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 Log4p/websocketHander.py diff --git a/Log4p/websocketHander.py b/Log4p/websocketHander.py deleted file mode 100644 index 93d5ed9..0000000 --- a/Log4p/websocketHander.py +++ /dev/null @@ -1,28 +0,0 @@ -import logging -import asyncio -import websockets - -class WebsocketHandler(logging.Handler): - def __init__(self, server_address): - super().__init__() - self.server_address = server_address - - async def send_log_async(self, message): - async with websockets.connect(self.server_address) as websocket: - await websocket.send(message) - - def send_log_sync(self, message): - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - loop.run_until_complete(self.send_log_async(message)) - - def emit(self, record): - log_entry = self.format(record) - - if asyncio.get_event_loop().is_running(): - asyncio.create_task(self.send_log_async(log_entry)) - else: - try: - self.send_log_sync(log_entry) - except Exception as e: - logging.warning("Failed to send log synchronously: %s", e) \ No newline at end of file