beans-logging-fastapi 1.0.2__tar.gz → 1.1.1__tar.gz

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.
Files changed (21) hide show
  1. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/PKG-INFO +6 -3
  2. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/README.md +4 -1
  3. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi/__version__.py +1 -1
  4. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi/_formats.py +10 -1
  5. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi/_middlewares.py +2 -0
  6. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi.egg-info/PKG-INFO +6 -3
  7. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/LICENCE.txt +0 -0
  8. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi/__init__.py +0 -0
  9. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi/_async_log.py +0 -0
  10. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi/_base.py +0 -0
  11. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi/_filters.py +0 -0
  12. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi/_handlers.py +0 -0
  13. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi.egg-info/SOURCES.txt +0 -0
  14. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi.egg-info/dependency_links.txt +0 -0
  15. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi.egg-info/requires.txt +0 -0
  16. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/beans_logging_fastapi.egg-info/top_level.txt +0 -0
  17. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/setup.cfg +0 -0
  18. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/setup.py +0 -0
  19. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/tests/__init__.py +0 -0
  20. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/tests/conftest.py +0 -0
  21. {beans_logging_fastapi-1.0.2 → beans_logging_fastapi-1.1.1}/tests/test_beans_logging_fastapi.py +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: beans_logging_fastapi
3
- Version: 1.0.2
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.0.2.tar.gz
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, msg_format=logger_loader.config.extra.http_file_format
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
 
@@ -146,6 +146,7 @@ logger:
146
146
  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'
147
147
  http_file_enabled: true
148
148
  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}'
149
+ http_file_tz: "localtime"
149
150
  http_log_path: "http/{app_name}.http.access.log"
150
151
  http_err_path: "http/{app_name}.http.err.log"
151
152
  http_json_enabled: true
@@ -180,7 +181,9 @@ logger: Logger = logger_loader.load()
180
181
 
181
182
  def _http_file_format(record: dict) -> str:
182
183
  _format = http_file_format(
183
- record=record, msg_format=logger_loader.config.extra.http_file_format
184
+ record=record,
185
+ msg_format=logger_loader.config.extra.http_file_format,
186
+ tz=logger_loader.config.extra.http_file_tz,
184
187
  )
185
188
  return _format
186
189
 
@@ -1,3 +1,3 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
- __version__ = "1.0.2"
3
+ __version__ = "1.1.1"
@@ -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
- _http_info["datetime"] = record["time"].isoformat(timespec="milliseconds")
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.0.2
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.0.2.tar.gz
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, msg_format=logger_loader.config.extra.http_file_format
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