@@ -15,47 +15,45 @@ Add a dependency to your application
1515
1616## Step 2: use the ` EcsEncoder `
1717
18- All you have to do is to use the ` co.elastic.logging.logback.EcsEncoder ` instead of the default pattern encoder
19- ``` xml
20- <encoder class =" co.elastic.logging.logback.EcsEncoder" >
21- <serviceName >my-application</serviceName >
22- </encoder >
23- ```
18+ ## Spring Boot applications
2419
25- ## Example ` logback.xml ` for Spring Boot applications
26-
20+ ` src/main/resources/logback-spring.xml `
2721``` xml
2822<?xml version =" 1.0" encoding =" UTF-8" ?>
2923<configuration >
24+ <property name =" LOG_FILE" value =" ${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/spring.log}" />
3025 <include resource =" org/springframework/boot/logging/logback/defaults.xml" />
31- <include resource =" org/springframework/boot/logging/logback/file-appender.xml" />
32- <appender name =" console" class =" ch.qos.logback.core.ConsoleAppender" >
33- <encoder class =" co.elastic.logging.logback.EcsEncoder" >
34- <serviceName >my-application</serviceName >
35- </encoder >
36- </appender >
37- <appender name =" json-file" class =" ch.qos.logback.core.rolling.RollingFileAppender" >
38- <encoder class =" co.elastic.logging.logback.EcsEncoder" >
39- <serviceName >my-application</serviceName >
40- </encoder >
41- <file >${LOG_FILE}.json</file >
42- <rollingPolicy class =" ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy" >
43- <fileNamePattern >${LOG_FILE}.json.%d{yyyy-MM-dd}.%i.gz</fileNamePattern >
44- <maxFileSize >${LOG_FILE_MAX_SIZE:-10MB}</maxFileSize >
45- <maxHistory >${LOG_FILE_MAX_HISTORY:-0}</maxHistory >
46- </rollingPolicy >
47- </appender >
48-
26+ <include resource =" org/springframework/boot/logging/logback/console-appender.xml" />
27+ <include resource =" org/springframework/boot/logging/logback/file-appender.xml" />
28+ <include resource =" co/elastic/logging/logback/boot/ecs-file-appender.xml" />
4929 <root level =" INFO" >
50- <appender-ref ref =" console" />
51- <appender-ref ref =" json-file" />
52- <!-- uncomment this if you also want to log in plain text
30+ <appender-ref ref =" CONSOLE" />
31+ <appender-ref ref =" ECS_JSON_FILE" />
5332 <appender-ref ref =" FILE" />
54- -->
5533 </root >
5634</configuration >
5735```
5836
37+ You also need to configure the following properties to your ` application.properties ` :
38+
39+ ``` properties
40+ spring.application.name =my-application
41+ # for Spring Boot 2.2.x+
42+ logging.file.name =/path/to/my-application.log
43+ # for older Spring Boot versions
44+ logging.file =/path/to/my-application.log
45+ ```
46+
47+ ## Other applications
48+
49+ All you have to do is to use the ` co.elastic.logging.logback.EcsEncoder ` instead of the default pattern encoder in ` logback.xml `
50+
51+ ``` xml
52+ <encoder class =" co.elastic.logging.logback.EcsEncoder" >
53+ <serviceName >my-application</serviceName >
54+ </encoder >
55+ ```
56+
5957## Encoder Parameters
6058
6159| Parameter name | Type | Default| Description|
0 commit comments