From 7f927414629543670311d657ff6bd4628ca7efcf 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:14 +0000 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20Log4p/HttpHander.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Log4p/HttpHander.py | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 Log4p/HttpHander.py diff --git a/Log4p/HttpHander.py b/Log4p/HttpHander.py deleted file mode 100644 index 4b9ddf7..0000000 --- a/Log4p/HttpHander.py +++ /dev/null @@ -1,35 +0,0 @@ -import logging -import requests -import httpx - -class HTTPhandler(logging.Handler): - def __init__(self, url): - super().__init__() - self.url = url - - def emit(self, record): - log_entry = self.format(record) - payload = {'log': log_entry} - try: - response = requests.post(self.url, json=payload) - if not response.ok: - raise ValueError(response.text) - except Exception as e: - logging.error("Failed to send log to %s: %s", self.url, e) - -class AsyncHTTPhandler(logging.Handler): - def __init__(self, url): - super().__init__() - self.url = url - - async def emit(self, record): - log_entry = self.format(record) - payload = {'log': log_entry} - try: - async with httpx.AsyncClient(timeout=120,max_redirects=5) as client: - response = await client.post(self.url, json=payload) - if not response.is_success: - raise ValueError(await response.text()) - except Exception as e: - logging.error("Failed to send log to %s: %s", self.url, e) -