izihawa-loglib 1.1.15__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.15
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:
@@ -9,7 +9,7 @@ class RequestContext:
9
9
  request_id_length: int = 12
10
10
 
11
11
  def __init__(
12
- self, **kwargs: dict[str, Any],
12
+ self, **kwargs: Any,
13
13
  ):
14
14
  self.default_fields = kwargs
15
15
  if not self.default_fields.get("request_id"):
@@ -29,16 +29,16 @@ class RequestContext:
29
29
  def generate_request_id(length):
30
30
  return generate_request_id(length)
31
31
 
32
- def add_default_fields(self, **fields: dict) -> None:
32
+ def add_default_fields(self, **fields: Any) -> None:
33
33
  self.default_fields.update(fields)
34
34
 
35
- def statbox(self, **kwargs: dict) -> None:
35
+ def statbox(self, **kwargs: Any) -> None:
36
36
  logging.getLogger("statbox").info(msg={**self.default_fields, **kwargs})
37
37
 
38
- def user_log(self, **kwargs: dict) -> None:
38
+ def user_log(self, **kwargs: Any) -> None:
39
39
  logging.getLogger("user").info(msg={**self.default_fields, **kwargs})
40
40
 
41
- def debug_log(self, **kwargs: dict) -> None:
41
+ def debug_log(self, **kwargs: Any) -> None:
42
42
  logging.getLogger("debug").debug(msg={**self.default_fields, **kwargs})
43
43
 
44
44
  def error_log(self, e, level=logging.ERROR, **fields) -> None:
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "izihawa_loglib"
3
- version = "1.1.15"
3
+ version = "1.1.17"
4
4
  description = "Izihawa log utilities"
5
5
  authors = ["Pasha Podolsky <ppodolsky@me.com>"]
6
6
  readme = "README.md"