python3-commons 0.16.2__py3-none-any.whl → 0.16.4__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.
@@ -1,14 +1,11 @@
1
1
  import logging
2
2
  import traceback
3
- from contextvars import ContextVar
4
3
  from datetime import UTC, datetime, date
5
4
  from decimal import Decimal
6
- from typing import Any, Final, Callable
5
+ from typing import Any, Final
7
6
 
8
7
  import msgspec
9
8
 
10
- correlation_id: ContextVar[str | None] = ContextVar('correlation_id', default=None)
11
-
12
9
  _DEFAULT_MAX_TB_CHARS: Final[int] = 8_000
13
10
  _STD_LOG_FIELDS: Final[frozenset[str]] = frozenset(
14
11
  {
@@ -36,7 +33,6 @@ _STD_LOG_FIELDS: Final[frozenset[str]] = frozenset(
36
33
  )
37
34
 
38
35
 
39
- # Keep normalization minimal and branch-based (unchanged)
40
36
  def _normalize(v: Any) -> Any:
41
37
  if isinstance(v, datetime | date):
42
38
  return v.isoformat()
@@ -54,38 +50,26 @@ def _normalize(v: Any) -> Any:
54
50
 
55
51
 
56
52
  class JSONFormatter(logging.Formatter):
57
- __slots__ = ('_get_correlation_id', '_max_tb_chars', '_encoder')
53
+ __slots__ = ('_max_tb_chars', '_encoder')
58
54
 
59
55
  def __init__(
60
- self,
61
- *,
62
- get_correlation_id: Callable[[], str | None] = lambda: correlation_id.get(),
63
- max_exc_tb_chars: int = _DEFAULT_MAX_TB_CHARS,
64
- **kwargs: Any,
56
+ self,
57
+ *,
58
+ max_exc_tb_chars: int = _DEFAULT_MAX_TB_CHARS,
59
+ **kwargs: Any,
65
60
  ) -> None:
66
61
  super().__init__(**kwargs)
67
62
 
68
- self._get_correlation_id = get_correlation_id
69
63
  self._max_tb_chars = max_exc_tb_chars
70
64
  self._encoder = msgspec.json.Encoder()
71
65
 
72
66
  def format(self, record: logging.LogRecord) -> str:
73
- # -------------------------
74
- # message (fast path)
75
- # -------------------------
76
67
  try:
77
68
  message = record.getMessage()
78
69
  except Exception:
79
70
  message = str(record.msg)
80
71
 
81
- # -------------------------
82
- # timestamp (no Formatter overhead)
83
- # -------------------------
84
72
  timestamp = datetime.fromtimestamp(record.created, UTC).isoformat().replace('+00:00', 'Z')
85
-
86
- # -------------------------
87
- # base log object (plain dict)
88
- # -------------------------
89
73
  log: dict[str, Any] = {
90
74
  'message': message,
91
75
  'level': record.levelname,
@@ -93,9 +77,6 @@ class JSONFormatter(logging.Formatter):
93
77
  'timestamp': timestamp,
94
78
  }
95
79
 
96
- if (corr_id := self._get_correlation_id()) is not None:
97
- log['correlation_id'] = corr_id
98
-
99
80
  if (exc_info := record.exc_info) and exc_info[0] is not None:
100
81
  exc_type, exc_value, exc_tb = exc_info
101
82
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python3-commons
3
- Version: 0.16.2
3
+ Version: 0.16.4
4
4
  Summary: Re-usable Python3 code
5
5
  Author-email: Oleg Korsak <kamikaze.is.waiting.you@gmail.com>
6
6
  License-Expression: GPL-3.0
@@ -20,15 +20,15 @@ python3_commons/db/models/rbac.py,sha256=ARRQ1tn_GThxiBiIs_6IKkGnIIv37SmVgSi90cb
20
20
  python3_commons/db/models/users.py,sha256=zNN3bNWl3cVE6dJtTPzmPSo_5d1SsBZwwkvIs-WzUBA,644
21
21
  python3_commons/log/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  python3_commons/log/filters.py,sha256=fuyjXZAUm-i2MNrxvFYag8F8Rr27x8W8MdV3ke6miSs,175
23
- python3_commons/log/formatters.py,sha256=uFZit5Xl7k2_hAVjqVG8-6nwFR3C7fKoeuW2jiz2S8M,3496
23
+ python3_commons/log/formatters.py,sha256=Jq01Z8VEM0VMU_gE5sZc2J-ZoMUH_emO-v6bte6g7ws,2723
24
24
  python3_commons/serializers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  python3_commons/serializers/common.py,sha256=VkA7C6wODvHk0QBXVX_x2JieDstihx3U__UFbTYf654,120
26
26
  python3_commons/serializers/json.py,sha256=UPkC3ps13x2C_NxwVV-K7Ewp4VjkVHSSUkJVw5k7Wiw,712
27
27
  python3_commons/serializers/msgpack.py,sha256=zESFBX34GsZ8rDu6Zk5V6CLT6P0mPilU0r04Ka6TblI,1474
28
28
  python3_commons/serializers/msgspec.py,sha256=upy5CBmK66-8hYnK5bAM_sZvZY5CAqZmzCw9GIF346I,2988
29
- python3_commons-0.16.2.dist-info/licenses/AUTHORS.rst,sha256=3R9JnfjfjH5RoPWOeqKFJgxVShSSfzQPIrEr1nxIo9Q,90
30
- python3_commons-0.16.2.dist-info/licenses/LICENSE,sha256=xxILuojHm4fKQOrMHPSslbyy6WuKAN2RiG74HbrYfzM,34575
31
- python3_commons-0.16.2.dist-info/METADATA,sha256=VHzo-ZDsPUIiAdIK3N2CHiOkc6EvdUgsSUjB6yAHBTc,1021
32
- python3_commons-0.16.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
33
- python3_commons-0.16.2.dist-info/top_level.txt,sha256=lJI6sCBf68eUHzupCnn2dzG10lH3jJKTWM_hrN1cQ7M,16
34
- python3_commons-0.16.2.dist-info/RECORD,,
29
+ python3_commons-0.16.4.dist-info/licenses/AUTHORS.rst,sha256=3R9JnfjfjH5RoPWOeqKFJgxVShSSfzQPIrEr1nxIo9Q,90
30
+ python3_commons-0.16.4.dist-info/licenses/LICENSE,sha256=xxILuojHm4fKQOrMHPSslbyy6WuKAN2RiG74HbrYfzM,34575
31
+ python3_commons-0.16.4.dist-info/METADATA,sha256=ZI4Gqt7VL4Y8BeCjcmzwUdfERtuFGBZu1G_GSDpHRtU,1021
32
+ python3_commons-0.16.4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
33
+ python3_commons-0.16.4.dist-info/top_level.txt,sha256=lJI6sCBf68eUHzupCnn2dzG10lH3jJKTWM_hrN1cQ7M,16
34
+ python3_commons-0.16.4.dist-info/RECORD,,