Skip to content

Commit 2526531

Browse files
authored
Adding log4j2 lookup example for predefined fields (#189)
1 parent e3d725a commit 2526531

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/tab-widgets/ecs-encoder.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ To include any custom field in the output, use following syntax:
197197
----
198198

199199
Custom fields are included in the order they are declared. The values support https://logging.apache.org/log4j/2.x/manual/lookups.html[lookups].
200+
This means that the `KeyValuePair` setting can be utilized to dynamically set predefined fields as well:
201+
202+
[source,xml]
203+
----
204+
<EcsLayout serviceName="myService">
205+
<KeyValuePair key="service.version" value="$${spring:project.version}"/>
206+
<KeyValuePair key="service.node.name" value="${env:HOSTNAME}"/>
207+
</EcsLayout>
208+
----
200209

201210
NOTE: The log4j2 `EcsLayout` does not allocate any memory (unless the log event contains an `Exception`) to reduce GC pressure.
202211
This is achieved by manually serializing JSON so that no intermediate JSON or map representation of a log event is needed.

0 commit comments

Comments
 (0)