File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -16,3 +16,33 @@ Add a dependency to your application
16
16
If you are not using a dependency management tool, like maven, you have to add both,
17
17
` log4j-ecs-layout ` and ` ecs-logging-core ` jars manually to the classpath.
18
18
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
+ ```
You can’t perform that action at this time.
0 commit comments