Skip to content

Commit 6909a26

Browse files
authored
AGE-103 : Updated logging handler with support for all datatype (#52)
* update log attribute handler * Release:v2.1.0 Handle all datatypes for log attributes
1 parent bb1d89e commit 6909a26

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

middleware/log.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ class MWLoggingHandler(LoggingHandler):
6464
@staticmethod
6565
def _get_attributes(record: LogRecord):
6666
attributes = LoggingHandler._get_attributes(record)
67-
if "request" in attributes:
68-
attributes["request"] = f'{attributes["request"].method} {attributes["request"].path}'
67+
68+
for key, value in attributes.items():
69+
if key == "request":
70+
if hasattr(value, "method") and hasattr(value, "path"):
71+
if len(vars(value)) == 2:
72+
attributes[key] = f'{value.method} {value.path}'
73+
else:
74+
attributes[key] = str(value)
75+
else:
76+
attributes[key] = str(value)
77+
elif not isinstance(value, (bool, str, bytes, int, float)):
78+
attributes[key] = str(value)
79+
6980
return attributes

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "middleware-io"
7-
version = "2.0.0"
7+
version = "2.1.0"
88
requires-python = ">=3.8"
99
description = "Middleware's APM tool enables Python developers to effortlessly monitor their applications, gathering distributed tracing, metrics, logs, and profiling data for valuable insights and performance optimization."
1010
authors = [{ name = "middleware-dev" }]

0 commit comments

Comments
 (0)