izihawa-loglib 1.1.16__tar.gz → 1.1.17__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: izihawa_loglib
3
- Version: 1.1.16
3
+ Version: 1.1.17
4
4
  Summary: Izihawa log utilities
5
5
  Author: Pasha Podolsky
6
6
  Author-email: ppodolsky@me.com
@@ -16,13 +16,19 @@ 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
- return record.msg.as_internal_dict()
19
+ d = record.msg.as_internal_dict()
20
20
  elif isinstance(record.msg, typing.Dict) or dataclasses.is_dataclass(
21
21
  record.msg
22
22
  ):
23
- return record.msg
23
+ d = record.msg
24
24
  else:
25
- return dict(message=super().format(record))
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
26
32
 
27
33
  def format(self, record):
28
34
  log_record = self._prepare(record)
@@ -37,7 +43,6 @@ class DefaultHttpFormatter(BaseFormatter):
37
43
  formatted_datetime = datetime.datetime.fromtimestamp(timestamp).strftime(
38
44
  DATETIME_FORMAT
39
45
  )
40
- client_ip = getattr(record, "client_ip", None)
41
46
  request_id = getattr(record, "request_id", None)
42
47
  method = getattr(record, "method", None)
43
48
  path = getattr(record, "path", None)
@@ -49,8 +54,6 @@ class DefaultHttpFormatter(BaseFormatter):
49
54
  process=os.getpid(),
50
55
  )
51
56
 
52
- if client_ip:
53
- log_record["client_ip"] = client_ip
54
57
  if request_id:
55
58
  log_record["request_id"] = request_id
56
59
  if method:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "izihawa_loglib"
3
- version = "1.1.16"
3
+ version = "1.1.17"
4
4
  description = "Izihawa log utilities"
5
5
  authors = ["Pasha Podolsky <ppodolsky@me.com>"]
6
6
  readme = "README.md"