@@ -15,47 +15,45 @@ Add a dependency to your application
15
15
16
16
## Step 2: use the ` EcsEncoder `
17
17
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
24
19
25
- ## Example ` logback.xml ` for Spring Boot applications
26
-
20
+ ` src/main/resources/logback-spring.xml `
27
21
``` xml
28
22
<?xml version =" 1.0" encoding =" UTF-8" ?>
29
23
<configuration >
24
+ <property name =" LOG_FILE" value =" ${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/spring.log}" />
30
25
<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" />
49
29
<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" />
53
32
<appender-ref ref =" FILE" />
54
- -->
55
33
</root >
56
34
</configuration >
57
35
```
58
36
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
+
59
57
## Encoder Parameters
60
58
61
59
| Parameter name | Type | Default| Description|
0 commit comments