izihawa-loglib 1.1.17__py3-none-any.whl → 1.1.19__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.
@@ -16,19 +16,13 @@ DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
16
16
  class BaseFormatter(logging.Formatter):
17
17
  def _prepare(self, record):
18
18
  if isinstance(record.msg, BaseError):
19
- d = record.msg.as_internal_dict()
19
+ return record.msg.as_internal_dict()
20
20
  elif isinstance(record.msg, typing.Dict) or dataclasses.is_dataclass(
21
21
  record.msg
22
22
  ):
23
- d = record.msg
23
+ return record.msg
24
24
  else:
25
- d = dict(message=super().format(record))
26
-
27
- client_ip = getattr(record, "client_ip", None)
28
- if client_ip:
29
- d["client_ip"] = str(client_ip)
30
-
31
- return d
25
+ return dict(message=super().format(record))
32
26
 
33
27
  def format(self, record):
34
28
  log_record = self._prepare(record)
@@ -43,6 +37,7 @@ class DefaultHttpFormatter(BaseFormatter):
43
37
  formatted_datetime = datetime.datetime.fromtimestamp(timestamp).strftime(
44
38
  DATETIME_FORMAT
45
39
  )
40
+ client_ip = getattr(record, "client_ip", None)
46
41
  request_id = getattr(record, "request_id", None)
47
42
  method = getattr(record, "method", None)
48
43
  path = getattr(record, "path", None)
@@ -54,6 +49,8 @@ class DefaultHttpFormatter(BaseFormatter):
54
49
  process=os.getpid(),
55
50
  )
56
51
 
52
+ if client_ip:
53
+ log_record["client_ip"] = client_ip
57
54
  if request_id:
58
55
  log_record["request_id"] = request_id
59
56
  if method:
@@ -76,7 +73,6 @@ class DefaultFormatter(BaseFormatter):
76
73
  formatted_datetime = datetime.datetime.fromtimestamp(timestamp).strftime(
77
74
  DATETIME_FORMAT
78
75
  )
79
-
80
76
  log_record.update(
81
77
  unixtime=int(timestamp),
82
78
  timestamp=int(timestamp * 1_000_000),
@@ -87,7 +83,7 @@ class DefaultFormatter(BaseFormatter):
87
83
 
88
84
  def format(self, record):
89
85
  log_record = self._prepare(record)
90
- return json.dumps(log_record).decode()
86
+ return json.dumps(log_record, default=str).decode()
91
87
 
92
88
 
93
89
  class TracebackFormatter(DefaultFormatter):
@@ -9,7 +9,8 @@ class RequestContext:
9
9
  request_id_length: int = 12
10
10
 
11
11
  def __init__(
12
- self, **kwargs: Any,
12
+ self,
13
+ **kwargs: Any,
13
14
  ):
14
15
  self.default_fields = kwargs
15
16
  if not self.default_fields.get("request_id"):
@@ -22,7 +23,7 @@ class RequestContext:
22
23
  return self.default_fields[name]
23
24
  except KeyError:
24
25
  classname = type(self).__name__
25
- msg = f'{classname!r} object has no attribute {name!r}'
26
+ msg = f"{classname!r} object has no attribute {name!r}"
26
27
  raise AttributeError(msg)
27
28
 
28
29
  @staticmethod
@@ -44,11 +45,3 @@ class RequestContext:
44
45
  def error_log(self, e, level=logging.ERROR, **fields) -> None:
45
46
  all_fields = {**self.default_fields, **fields}
46
47
  error_log(e, level=level, **all_fields)
47
-
48
- def to_default_headers(self) -> dict[str, Any]:
49
- headers = {}
50
- if request_id := self.default_fields.get("request_id"):
51
- headers["X-Request-Id"] = request_id
52
- if client_id := self.default_fields.get("client_id"):
53
- headers["X-Client-Id"] = client_id
54
- return headers
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: izihawa_loglib
3
- Version: 1.1.17
3
+ Version: 1.1.19
4
4
  Summary: Izihawa log utilities
5
5
  Author: Pasha Podolsky
6
6
  Author-email: ppodolsky@me.com
@@ -0,0 +1,7 @@
1
+ izihawa_loglib/__init__.py,sha256=E6ab53TTvjIwCOv8Wl8SbNyaPjXkOlim2fryehPgiEA,1005
2
+ izihawa_loglib/formatters.py,sha256=CdeIbFm4HOcg81yfv7oRjawf_A6Mv5G06zRrW1JZY6o,2908
3
+ izihawa_loglib/handlers.py,sha256=GU7SLTgia1pgY9ufvUQSsMMEweaAGe6B7ibKn2wLb1I,1122
4
+ izihawa_loglib/request_context.py,sha256=VLwoUFcWVJ8cDNjVgGuv-RxKEDVbxZ4W-cG-LgKjMwg,1509
5
+ izihawa_loglib-1.1.19.dist-info/METADATA,sha256=7jIvLA3Krt4lnzk2b7bP10Axz2c3jn7ahoXFeNQqGjg,658
6
+ izihawa_loglib-1.1.19.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
7
+ izihawa_loglib-1.1.19.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- izihawa_loglib/__init__.py,sha256=E6ab53TTvjIwCOv8Wl8SbNyaPjXkOlim2fryehPgiEA,1005
2
- izihawa_loglib/formatters.py,sha256=2GRS3LFmau1IId3GbmDw1T8URRjNZB9Zfzspvy8LPO0,2902
3
- izihawa_loglib/handlers.py,sha256=GU7SLTgia1pgY9ufvUQSsMMEweaAGe6B7ibKn2wLb1I,1122
4
- izihawa_loglib/request_context.py,sha256=A3T-dsIytgRezhmxu0MdE6ZPc0ZYbuE-QGGIQOVY6q8,1820
5
- izihawa_loglib-1.1.17.dist-info/METADATA,sha256=WoD-iXABWIewXWSyPoNZOWNNl7dXWytuiY8BhrpDeBI,658
6
- izihawa_loglib-1.1.17.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
7
- izihawa_loglib-1.1.17.dist-info/RECORD,,