beans-logging-fastapi 1.0.2__py3-none-any.whl → 1.1.1__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.
- beans_logging_fastapi/__version__.py +1 -1
- beans_logging_fastapi/_formats.py +10 -1
- beans_logging_fastapi/_middlewares.py +2 -0
- {beans_logging_fastapi-1.0.2.dist-info → beans_logging_fastapi-1.1.1.dist-info}/METADATA +6 -3
- {beans_logging_fastapi-1.0.2.dist-info → beans_logging_fastapi-1.1.1.dist-info}/RECORD +8 -8
- {beans_logging_fastapi-1.0.2.dist-info → beans_logging_fastapi-1.1.1.dist-info}/WHEEL +1 -1
- {beans_logging_fastapi-1.0.2.dist-info → beans_logging_fastapi-1.1.1.dist-info}/LICENCE.txt +0 -0
- {beans_logging_fastapi-1.0.2.dist-info → beans_logging_fastapi-1.1.1.dist-info}/top_level.txt +0 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
|
|
3
3
|
from typing import Dict, Any
|
|
4
|
+
from zoneinfo import ZoneInfo
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
def http_file_format(
|
|
7
8
|
record: dict,
|
|
8
9
|
msg_format: str = '{client_host} {request_id} {user_id} [{datetime}] "{method} {url_path} HTTP/{http_version}" {status_code} {content_length} "{h_referer}" "{h_user_agent}" {response_time}',
|
|
10
|
+
tz: str = "localtime",
|
|
9
11
|
) -> str:
|
|
10
12
|
"""Http access log file format.
|
|
11
13
|
|
|
@@ -22,7 +24,14 @@ def http_file_format(
|
|
|
22
24
|
if "http_message" not in record:
|
|
23
25
|
_http_info: Dict[str, Any] = record["extra"]["http_info"]
|
|
24
26
|
if "datetime" not in _http_info:
|
|
25
|
-
|
|
27
|
+
_dt = record["time"]
|
|
28
|
+
if tz != "localtime":
|
|
29
|
+
if not _dt.tzinfo:
|
|
30
|
+
_dt = _dt.replace(tzinfo=ZoneInfo("UTC"))
|
|
31
|
+
|
|
32
|
+
_dt = _dt.astimezone(ZoneInfo(tz))
|
|
33
|
+
|
|
34
|
+
_http_info["datetime"] = _dt.isoformat(timespec="milliseconds")
|
|
26
35
|
|
|
27
36
|
if "content_length" not in _http_info:
|
|
28
37
|
_http_info["content_length"] = 0
|
|
@@ -137,6 +137,8 @@ class RequestHTTPInfoMiddleware(BaseHTTPMiddleware):
|
|
|
137
137
|
_http_info["url_path"] = _http_info["url_path"].replace("{", "{{")
|
|
138
138
|
if "}" in _http_info["url_path"]:
|
|
139
139
|
_http_info["url_path"] = _http_info["url_path"].replace("}", "}}")
|
|
140
|
+
if "<" in _http_info["url_path"]:
|
|
141
|
+
_http_info["url_path"] = _http_info["url_path"].replace("<", "\<")
|
|
140
142
|
if request.url.query:
|
|
141
143
|
_http_info["url_path"] = f"{request.url.path}?{request.url.query}"
|
|
142
144
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: beans-logging-fastapi
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.1
|
|
4
4
|
Summary: 'beans_logging_fastapi' is a middleware for FastAPI to log HTTP access. It is based on 'beans-logging' package.
|
|
5
5
|
Home-page: https://github.com/bybatkhuu/module.fastapi-logging
|
|
6
|
-
Download-URL: https://github.com/bybatkhuu/module.fastapi-logging/archive/v1.
|
|
6
|
+
Download-URL: https://github.com/bybatkhuu/module.fastapi-logging/archive/v1.1.1.tar.gz
|
|
7
7
|
Author: Batkhuu Byambajav
|
|
8
8
|
Author-email: batkhuu10@gmail.com
|
|
9
9
|
License: MIT
|
|
@@ -170,6 +170,7 @@ logger:
|
|
|
170
170
|
http_std_msg_format: '<n><w>[{request_id}]</w></n> {client_host} {user_id} "<u>{method} {url_path}</u> HTTP/{http_version}" {status_code} {content_length}B {response_time}ms'
|
|
171
171
|
http_file_enabled: true
|
|
172
172
|
http_file_format: '{client_host} {request_id} {user_id} [{datetime}] "{method} {url_path} HTTP/{http_version}" {status_code} {content_length} "{h_referer}" "{h_user_agent}" {response_time}'
|
|
173
|
+
http_file_tz: "localtime"
|
|
173
174
|
http_log_path: "http/{app_name}.http.access.log"
|
|
174
175
|
http_err_path: "http/{app_name}.http.err.log"
|
|
175
176
|
http_json_enabled: true
|
|
@@ -204,7 +205,9 @@ logger: Logger = logger_loader.load()
|
|
|
204
205
|
|
|
205
206
|
def _http_file_format(record: dict) -> str:
|
|
206
207
|
_format = http_file_format(
|
|
207
|
-
record=record,
|
|
208
|
+
record=record,
|
|
209
|
+
msg_format=logger_loader.config.extra.http_file_format,
|
|
210
|
+
tz=logger_loader.config.extra.http_file_tz,
|
|
208
211
|
)
|
|
209
212
|
return _format
|
|
210
213
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
beans_logging_fastapi/__init__.py,sha256=BRaF1AtJeVBvYtDyvx9YUBUe7Ez632UAwVW6rUQU72I,874
|
|
2
|
-
beans_logging_fastapi/__version__.py,sha256=
|
|
2
|
+
beans_logging_fastapi/__version__.py,sha256=vaO-yG68LsdKNrjwKiIqxA34q000eeRpru3EyLGSxsY,47
|
|
3
3
|
beans_logging_fastapi/_async_log.py,sha256=2J-LBW0IQRCtZOfcYHZSUSbzQipWF-MuWbXgd6tqP9Q,3334
|
|
4
4
|
beans_logging_fastapi/_base.py,sha256=ChpSFJ0yXUUdgV9Y-2SyrjPRuGHdYCf5UvMDxnPRAGg,4186
|
|
5
5
|
beans_logging_fastapi/_filters.py,sha256=SmluD4RDMk_wsRJVSpE5jp7AylotYJy2N6aw9AVWwFI,541
|
|
6
|
-
beans_logging_fastapi/_formats.py,sha256=
|
|
6
|
+
beans_logging_fastapi/_formats.py,sha256=MdS5x5EV7BVWEjVstQCeQn8XUz3qW12ltQS8-rNrCKc,2166
|
|
7
7
|
beans_logging_fastapi/_handlers.py,sha256=eEgQD7ho6dqLzUfoN7CNAq7hD-fd97oeo-HROb6x1xk,2794
|
|
8
|
-
beans_logging_fastapi/_middlewares.py,sha256=
|
|
8
|
+
beans_logging_fastapi/_middlewares.py,sha256=h9-turKSGnK__4mLAId3Slno3avz7Hu9lNpdmoepjY0,9278
|
|
9
9
|
tests/__init__.py,sha256=iwhKnzeBJLKxpRVjvzwiRE63_zNpIBfaKLITauVph-0,24
|
|
10
10
|
tests/conftest.py,sha256=ycEL83-UMU-fcXQUZWTCNEPcBOZ38pzhoCPpXpCjIEM,319
|
|
11
11
|
tests/test_beans_logging_fastapi.py,sha256=khxZzk-UZJU4BfM3KLytzKZATnsjsYts0UJqn1UB5cU,489
|
|
12
|
-
beans_logging_fastapi-1.
|
|
13
|
-
beans_logging_fastapi-1.
|
|
14
|
-
beans_logging_fastapi-1.
|
|
15
|
-
beans_logging_fastapi-1.
|
|
16
|
-
beans_logging_fastapi-1.
|
|
12
|
+
beans_logging_fastapi-1.1.1.dist-info/LICENCE.txt,sha256=8jrXqC7FZbke39LPGo_mUFR81CkoUCP_vyefZjlQDOg,1074
|
|
13
|
+
beans_logging_fastapi-1.1.1.dist-info/METADATA,sha256=_Jw2qKu3bDukUEkmJI8goSLgIsoalx5G4D7wqqWrfTE,12502
|
|
14
|
+
beans_logging_fastapi-1.1.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
15
|
+
beans_logging_fastapi-1.1.1.dist-info/top_level.txt,sha256=i97pAfk2NcT9DA7cPsBmF6_90GzNObQ9UJpZFuXdt1s,28
|
|
16
|
+
beans_logging_fastapi-1.1.1.dist-info/RECORD,,
|
|
File without changes
|
{beans_logging_fastapi-1.0.2.dist-info → beans_logging_fastapi-1.1.1.dist-info}/top_level.txt
RENAMED
|
File without changes
|