izihawa-loglib 1.1.19__tar.gz → 1.1.21__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.19
3
+ Version: 1.1.21
4
4
  Summary: Izihawa log utilities
5
5
  Author: Pasha Podolsky
6
6
  Author-email: ppodolsky@me.com
@@ -37,8 +37,9 @@ class DefaultHttpFormatter(BaseFormatter):
37
37
  formatted_datetime = datetime.datetime.fromtimestamp(timestamp).strftime(
38
38
  DATETIME_FORMAT
39
39
  )
40
- client_ip = getattr(record, "client_ip", None)
40
+ real_ip = getattr(record, "real_ip", None)
41
41
  request_id = getattr(record, "request_id", None)
42
+ client_id = getattr(record, "client_id", None)
42
43
  method = getattr(record, "method", None)
43
44
  path = getattr(record, "path", None)
44
45
 
@@ -49,10 +50,12 @@ class DefaultHttpFormatter(BaseFormatter):
49
50
  process=os.getpid(),
50
51
  )
51
52
 
52
- if client_ip:
53
- log_record["client_ip"] = client_ip
53
+ if real_ip:
54
+ log_record["real_ip"] = real_ip
54
55
  if request_id:
55
56
  log_record["request_id"] = request_id
57
+ if client_id:
58
+ log_record["client_id"] = client_id
56
59
  if method:
57
60
  log_record["method"] = method
58
61
  if path:
@@ -1,4 +1,5 @@
1
1
  import logging
2
+ import typing
2
3
  from typing import Any
3
4
 
4
5
  from izihawa_loglib import error_log
@@ -13,6 +14,7 @@ class RequestContext:
13
14
  **kwargs: Any,
14
15
  ):
15
16
  self.default_fields = kwargs
17
+ self.context_fields = {}
16
18
  if not self.default_fields.get("request_id"):
17
19
  self.default_fields["request_id"] = RequestContext.generate_request_id(
18
20
  self.request_id_length
@@ -22,9 +24,12 @@ class RequestContext:
22
24
  try:
23
25
  return self.default_fields[name]
24
26
  except KeyError:
25
- classname = type(self).__name__
26
- msg = f"{classname!r} object has no attribute {name!r}"
27
- raise AttributeError(msg)
27
+ try:
28
+ return self.context_fields[name]
29
+ except KeyError:
30
+ classname = type(self).__name__
31
+ msg = f"{classname!r} object has no attribute {name!r}"
32
+ raise AttributeError(msg)
28
33
 
29
34
  @staticmethod
30
35
  def generate_request_id(length):
@@ -33,6 +38,9 @@ class RequestContext:
33
38
  def add_default_fields(self, **fields: Any) -> None:
34
39
  self.default_fields.update(fields)
35
40
 
41
+ def add_context_fields(self, **fields: Any) -> None:
42
+ self.context_fields.update(fields)
43
+
36
44
  def statbox(self, **kwargs: Any) -> None:
37
45
  logging.getLogger("statbox").info(msg={**self.default_fields, **kwargs})
38
46
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "izihawa_loglib"
3
- version = "1.1.19"
3
+ version = "1.1.21"
4
4
  description = "Izihawa log utilities"
5
5
  authors = ["Pasha Podolsky <ppodolsky@me.com>"]
6
6
  readme = "README.md"