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/src/main/asciidoc/se/guides/logging.adoc
+14-9Lines changed: 14 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,8 +149,8 @@ For more information see link:{helidon-github-examples-url}/logging/slf4j[Helido
149
149
150
150
== Mapped Diagnostic Context (MDC) support
151
151
152
-
The Mapped Diagnostic Context provides a mechanism for application code to store
153
-
values in a context that are then included in log output. These values could
152
+
The Mapped Diagnostic Context provides a mechanism for Helidon and application code to store
153
+
values in a context that can then be included in log output. These values could
154
154
be a tracing ID, the current user, or a similar contextual value, and they are
155
155
propagated by Helidon across threads.
156
156
@@ -161,21 +161,26 @@ but also works with the other supported frameworks (slf4j or log4j).
161
161
162
162
To use Helidon MDC, you need to do three things:
163
163
164
-
1. Add a dependencies on one of the supported logging frameworks. See previous sections.
164
+
1. Add a dependency on one of the supported logging frameworks. See previous sections.
165
165
2. Store values in the MDC in your code.
166
166
3. Configure logging to display the values in its output.
167
167
168
+
=== MDC values provided by Helidon
169
+
If you include tracing in your project, Helidon automatically provides the MDC key `trace_id`. Logging inserts the trace ID of the current span (if there is one) or the string "none" if no span is active.
170
+
168
171
=== Storing values in MDC
169
172
170
-
To set values in the MDC you can use `io.helidon.logging.common.HelidonMdc` class:
173
+
To set your own values in the MDC you can use `io.helidon.logging.common.HelidonMdc` class:
<1> Stores an attribute named "name" with the fixed value "Joe" in the MDC.
181
+
<2> Stores an attribute named "otherName" with the given `Supplier<String>`.
176
182
177
-
This will store an attribute named "name" with the value "Joe" in the MDC so that it can be
178
-
extracted later in log output.
183
+
The `set(<String, String>`) method associates the name with a fixed value. The `set(<String>, <Supplier<String>>) form associates the name with a lambda or method reference. This second form might be useful if your code (or Helidon) maintains the value you want to log in some context that your code can access and if that value changes as the server runs. In both cases, when your logging format refers to the name logging extracts the corresponding fixed value or invoked the supplier to obtain the value, using the result in log output.
179
184
180
185
`HelidonMdc` works with the supported logging frameworks. But if you prefer, you can
181
186
use a logging framework specific API. Such as `org.slf4j.MDC` or `org.apache.logging.log4j.ThreadContext` instead.
@@ -231,4 +236,4 @@ for MDC is you can use the token `%X{name}` to reference MDC values in the log o
0 commit comments