internal 1.0.7__py3-none-any.whl → 1.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of internal might be problematic. Click here for more details.

internal/base_config.py CHANGED
@@ -8,6 +8,8 @@ class BaseConfig(BaseSettings):
8
8
 
9
9
  OPEN_API_URL: str = "/openapi.json"
10
10
 
11
+ LOGGER_REQUEST_ENABLE: bool = True
12
+
11
13
  # Request
12
14
  REQUEST_VERIFY_SSL: bool = True
13
15
  REQUEST_PROXY: str = ''
internal/base_factory.py CHANGED
@@ -18,6 +18,7 @@ from .exception.base_exception import InternalBaseException
18
18
  from .ext.amazon import aws
19
19
  from .http.requests import async_request
20
20
  from .http.responses import async_response
21
+ from .middleware.log_request import LogRequestMiddleware
21
22
  from .utils import update_dict_with_cast
22
23
 
23
24
 
@@ -68,6 +69,9 @@ class BaseFactory(metaclass=ABCMeta):
68
69
  self.__setup_cloud_log(app)
69
70
  self.__load_cloud_config(app)
70
71
 
72
+ if self.get_app_config().LOGGER_REQUEST_ENABLE:
73
+ app.add_middleware(LogRequestMiddleware)
74
+
71
75
  mongodb = database.MongoDB(self.get_app_config().DATABASE_USERNAME, self.get_app_config().DATABASE_PASSWORD,
72
76
  self.get_app_config().DATABASE_HOST, self.get_app_config().DATABASE_PORT,
73
77
  self.get_app_config().DATABASE_NAME,
File without changes
@@ -0,0 +1,25 @@
1
+ import time
2
+
3
+ from fastapi import FastAPI, Request
4
+ from starlette.middleware.base import BaseHTTPMiddleware
5
+
6
+
7
+ class LogRequestMiddleware(BaseHTTPMiddleware):
8
+ def __init__(self, app: FastAPI):
9
+ super().__init__(app)
10
+ self.app = app
11
+
12
+ async def dispatch(self, request: Request, call_next):
13
+ # 记录请求的URL和参数
14
+ url = request.url.path
15
+ params = dict(request.query_params)
16
+ body = await request.body()
17
+ self.app.state.logger.info(f"URL: {url} - Params: {params} - Body: {body}")
18
+
19
+ # 记录请求处理时间
20
+ start_time = time.time()
21
+ response = await call_next(request)
22
+ process_time = time.time() - start_time
23
+
24
+ self.app.state.logger.info(f"Completed in {process_time:.4f} seconds")
25
+ return response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: internal
3
- Version: 1.0.7
3
+ Version: 1.0.8
4
4
  Summary:
5
5
  Author: Ray
6
6
  Author-email: ray@cruisys.com
@@ -1,6 +1,6 @@
1
1
  internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- internal/base_config.py,sha256=49-RBoIwc0gbxqJXDuIbyfIYN1LlGR3UOdiVnJDcKZs,1715
3
- internal/base_factory.py,sha256=QHYORSlyxM33rP2jIuqtVibdefguurlBUwC6GBNcK2s,7662
2
+ internal/base_config.py,sha256=5-s2muyaLOGKhrq8kVqq0qaXFD09FrcQZCAFmw1FQtk,1755
3
+ internal/base_factory.py,sha256=VkRrmCZOuwFriezqhsX5RziuzRSoJvsH6Wn3QD5sBHs,7829
4
4
  internal/common_enum/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  internal/common_enum/contact_type.py,sha256=uwZjxImXltMmfoAbe-1IeK3ry-p_wJ-wPPWR6NB7WXM,142
6
6
  internal/common_enum/event_type.py,sha256=jMuqiVGhOcYaJ7rYpn-nSpVH08bUsycF7ezHqpXk_Mc,114
@@ -20,10 +20,12 @@ internal/http/requests.py,sha256=C2MfPaRcFuF8p52aPwtOyzXQEVu5MWMY8UUCrggxONw,167
20
20
  internal/http/responses.py,sha256=b3Qc-iQmoYyFYrFv_lCQKbMNUu6My53YRRbUMn_1QoI,1687
21
21
  internal/interface/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  internal/interface/base_interface.py,sha256=R5MmO5oa5-ORPV_adkegLVCwsVio2zFOuQFGiby3khs,340
23
+ internal/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
+ internal/middleware/log_request.py,sha256=Zdv5qyJ5F1meQ7tyni7i1GEOKtd03F1vIVlxObrSKUU,806
23
25
  internal/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
26
  internal/model/base_model.py,sha256=svULVdROpcnmTyhIbZ7M6pn40vhb_qIZ5W2CEyuEWZE,3002
25
27
  internal/model/operate.py,sha256=luEoP_Asvso_11qz1SAE1Kn5KxAnDRptM0VylC5tNik,1493
26
28
  internal/utils.py,sha256=0SubS0iUhDvjSX1F4TykasA5-enYJzt2VH-f7_0BnjI,1509
27
- internal-1.0.7.dist-info/METADATA,sha256=j_CQBl-xf89pxjJu_E3SuC1ojJ1iBCrVa2xNHU7Un4M,624
28
- internal-1.0.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
29
- internal-1.0.7.dist-info/RECORD,,
29
+ internal-1.0.8.dist-info/METADATA,sha256=G7l5s22lLmbQxgKpScnyEBgQkG3aZ_IDixpWsZobvK4,624
30
+ internal-1.0.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
31
+ internal-1.0.8.dist-info/RECORD,,