izihawa-loglib 1.1.17__py3-none-any.whl → 1.1.18__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):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: izihawa_loglib
3
- Version: 1.1.17
3
+ Version: 1.1.18
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=A3T-dsIytgRezhmxu0MdE6ZPc0ZYbuE-QGGIQOVY6q8,1820
5
+ izihawa_loglib-1.1.18.dist-info/METADATA,sha256=rM6tLNelHiO9qyhWPRdYbO250ae1qwLWkNlHDAoG_CE,658
6
+ izihawa_loglib-1.1.18.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
7
+ izihawa_loglib-1.1.18.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,,