Skip to content

Commit b7151a9

Browse files
author
Victor Laborie
authored
Add example for Log4j ECS Layout (#95)
1 parent d729141 commit b7151a9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

log4j-ecs-layout/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,33 @@ Add a dependency to your application
1616
If you are not using a dependency management tool, like maven, you have to add both,
1717
`log4j-ecs-layout` and `ecs-logging-core` jars manually to the classpath.
1818
For example to the `$CATALINA_HOME/lib` directory.
19+
20+
## Step 2: use the `EcsLayout`
21+
22+
Instead of the usual layout class `"org.apache.log4j.PatternLayout"`, use `"co.elastic.logging.log4j.EcsLayout"`.
23+
24+
## Example
25+
26+
```xml
27+
<?xml version="1.0" encoding="UTF-8"?>
28+
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
29+
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
30+
<appender name="LogToConsole" class="org.apache.log4j.ConsoleAppender">
31+
<param name="Target" value="System.out"/>
32+
<layout class="co.elastic.logging.log4j.EcsLayout">
33+
<param name="serviceName" value="my-app"/>
34+
</layout>
35+
</appender>
36+
<appender name="LogToFile" class="org.apache.log4j.RollingFileAppender">
37+
<param name="File" value="logs/app.log"/>
38+
<layout class="co.elastic.logging.log4j.EcsLayout">
39+
<param name="serviceName" value="my-app"/>
40+
</layout>
41+
</appender>
42+
<root>
43+
<priority value="INFO"/>
44+
<appender-ref ref="LogToFile"/>
45+
<appender-ref ref="LogToConsole"/>
46+
</root>
47+
</log4j:configuration>
48+
```

0 commit comments

Comments
 (0)