You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/adrs/006-logging-strategy.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,12 +38,13 @@ The approach emphasizes descriptive, human-readable logs with structured request
38
38
Logs should read naturally and provide enough context for a developer to understand what happened without consulting the code.
39
39
While descriptiveness is a priority, follow the `metric=value` pattern where practical to include additional details with extensibility in mind.
40
40
Check out the example below.
41
+
41
42
```[reqId=e3eaa45c] OpenAI request completed successfully with duration=1628ms, size=1,2KB.```
42
43
43
-
***Correlate related logs.**
44
+
***Correlate logs.**
44
45
Include a request identifier (e.g., `reqId`) in per-request logs to assist with correlation and debugging.
45
46
46
-
***Exception logging security.**
47
+
***Exception logging.**
47
48
When logging exceptions, use standard logging methods (e.g., `log.error("Operation failed", exception)`) rather than serializing exception objects.
48
49
Exception objects may contain custom fields with sensitive data that could be exposed through JSON serialization or custom `toString()` implementations.
49
50
@@ -61,14 +62,14 @@ The approach emphasizes descriptive, human-readable logs with structured request
61
62
Use the WARNING level only for actionable or genuinely concerning conditions.
62
63
Do not use it as a placeholder or for expected transient states.
63
64
64
-
***Explicit request lifecycle logging.**
65
+
***Explicit request logging.**
65
66
Always log at **request start** to provide immediate visibility that an operation has begun.
66
67
This helps users understand that their request is being processed even before a result is available.
67
68
Do not rely solely on response-time logging — requests may fail, hang, or take long durations.
68
69
This approach also avoids the need for stack-trace investigation when surface error responses are ambiguous.
69
70
70
71
***Performance-aware logging.**
71
-
If a log statement requires computation or inference to generate information, guard it with a log-level check (e.g., `if (log.isDebugEnabled())`) or other available context to avoid unnecessary overhead when that level is disabled.
72
+
If a log statement requires computation or inference to generate information, guard it with a log-level check (e.g., `if (log.isDebugEnabled())`) or other available context to avoid unnecessary overhead.
72
73
73
74
---
74
75
@@ -81,15 +82,14 @@ The approach emphasizes descriptive, human-readable logs with structured request
81
82
Set MDC values deliberately and close to their scope of relevance.
82
83
Per-request MDC context must be cleared when the response completes.
83
84
Avoid setting per-request values in long-lived objects that outlive the request lifecycle, as this can result in corrupted or incomplete log context.
84
-
Setting per-request context outside of blocks or objects that are not invoked per-request can lead to incomplete MDC states which will corrupt logs produced.
85
85
86
86
***Granular clearing only.**
87
87
Never clear the entire MDC context.
88
88
Instead, remove entries key-by-key to preserve unrelated context items that may remain valid for longer periods.
89
89
90
90
***Centralized MDC management.**
91
91
Avoid using magic strings for MDC keys or values.
92
-
Define them in a dedicated structure or utility (e.g., `MdcKeys` class) to ensure discoverability and prevent errors during refactoring.
92
+
Define them in a dedicated structure or utility (e.g., `RequestlogContext` class) to ensure discoverability and prevent errors during refactoring.
93
93
94
94
***Responsibility and ownership.**
95
95
The component or class that sets MDC context values is also responsible for clearing them.
0 commit comments