|
1 |
| -<?xml version="1.0" encoding="UTF-8"?> |
2 |
| -<configuration debug="false" scan="true"> |
3 |
| - <include resource="org/springframework/boot/logging/logback/defaults.xml"/> |
4 |
| - <springProperty scope="context" name="applicationName" source="spring.application.name"/> |
5 |
| - <property name="FILE_LOG_PATTERN" |
6 |
| - value="%d{yyyy-MM-dd HH:mm:ss.SSS} -- [${applicationName}] -- %5p ${PID:- } --- [%t] [%X{sessionId}] %-40.40logger{39} : %m%n%wex"/> |
7 |
| - |
8 |
| - <property name="CONSOLE_LOG_PATTERN" |
9 |
| - value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr([${applicationName:-}]){yellow} %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/> |
10 |
| - |
11 |
| - <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> |
12 |
| - <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> |
13 |
| - <level>INFO</level> |
14 |
| - </filter> |
15 |
| - <encoder> |
16 |
| - <pattern>${CONSOLE_LOG_PATTERN}</pattern> |
17 |
| - <charset>utf8</charset> |
18 |
| - </encoder> |
19 |
| - </appender> |
20 |
| - |
21 |
| - <root level="TRACE"> |
22 |
| - <appender-ref ref="console"/> |
23 |
| - </root> |
24 |
| - |
25 |
| -</configuration> |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<configuration debug="false" scan="true"> |
| 3 | + <include resource="org/springframework/boot/logging/logback/defaults.xml"/> |
| 4 | + <springProperty scope="context" name="applicationName" source="spring.application.name"/> |
| 5 | + <springProperty scope="context" name="applicationVersion" source="info.build.version"/> |
| 6 | + <springProperty scope="context" name="logstashHost" source="logstash.host"/> |
| 7 | + <springProperty scope="context" name="environment" source="spring.profiles.active"/> |
| 8 | + |
| 9 | + <property name="FILE_LOG_PATTERN" |
| 10 | + value="%d{yyyy-MM-dd HH:mm:ss.SSS} -- [${applicationName}] -- %5p ${PID:- } --- [%t] [%X{sessionId}] %-40.40logger{39} : %m%n%wex"/> |
| 11 | + |
| 12 | + <property name="CONSOLE_LOG_PATTERN" |
| 13 | + value="%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr([${applicationName:-}]){yellow} %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/> |
| 14 | + |
| 15 | + <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> |
| 16 | + <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> |
| 17 | + <level>INFO</level> |
| 18 | + </filter> |
| 19 | + <encoder> |
| 20 | + <pattern>${CONSOLE_LOG_PATTERN}</pattern> |
| 21 | + <charset>utf8</charset> |
| 22 | + </encoder> |
| 23 | + </appender> |
| 24 | + |
| 25 | + <appender name="logstash" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> |
| 26 | + <param name="Encoding" value="UTF-8"/> |
| 27 | + <keepAliveDuration>5 minutes</keepAliveDuration> <!-- Send keep alive message if an event has not occurred for length of the duration --> |
| 28 | + <reconnectionDelay>10 second</reconnectionDelay> <!-- TCP appender waits for duration (default 30 sec) before reattempting to connect on failure --> |
| 29 | + <remoteHost>${logstashHost}</remoteHost> |
| 30 | + <port>32245</port> |
| 31 | + <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> |
| 32 | + <level>WARN</level> |
| 33 | + </filter> |
| 34 | + <!-- Encoder is required --> |
| 35 | + <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> |
| 36 | + <providers> |
| 37 | + <timestamp> |
| 38 | + <timeZone>UTC</timeZone> |
| 39 | + </timestamp> |
| 40 | + <mdc/> <!-- MDC variables on the Thread will be written as JSON fields--> |
| 41 | + <context/> <!--Outputs entries from logback's context --> |
| 42 | + <logLevel/> |
| 43 | + <loggerName/> |
| 44 | + <pattern> |
| 45 | + <pattern> |
| 46 | + { |
| 47 | + "applicationName": "${applicationName}", |
| 48 | + "applicationVersion": "${applicationVersion}", |
| 49 | + "environment": "${environment}" |
| 50 | + } |
| 51 | + </pattern> |
| 52 | + </pattern> |
| 53 | + <threadName/> |
| 54 | + <message/> |
| 55 | + <logstashMarkers/> <!-- Useful so we can add extra information for specific log lines as Markers--> |
| 56 | + <arguments/> <!--or through StructuredArguments--> |
| 57 | + <stackTrace> |
| 58 | + <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter"> |
| 59 | + <exclude>net\.sf\.cglib\..*</exclude> |
| 60 | + <exclude>org\.apache\.coyote\..*</exclude> |
| 61 | + <exclude>org\.apache\.catalina\..*</exclude> |
| 62 | + <exclude>org\.apache\.tomcat\..*</exclude> |
| 63 | + <exclude>org\.springframework\.web\.servlet\..*</exclude> |
| 64 | + <exclude>^sun\.reflect\..*\.invoke</exclude> |
| 65 | + <maxDepthPerThrowable>30</maxDepthPerThrowable> |
| 66 | + <rootCauseFirst>true</rootCauseFirst> |
| 67 | + <maxLength>2048</maxLength> |
| 68 | + <!--<shortenedClassNameLength>20</shortenedClassNameLength>--> |
| 69 | + </throwableConverter> |
| 70 | + </stackTrace> |
| 71 | + </providers> |
| 72 | + </encoder> |
| 73 | + </appender> |
| 74 | + |
| 75 | + <springProfile name="!production"> |
| 76 | + <root level="DEBUG"> |
| 77 | + <appender-ref ref="console"/> |
| 78 | + </root> |
| 79 | + </springProfile> |
| 80 | + <springProfile name="production"> |
| 81 | + <root level="WARN"> |
| 82 | + <appender-ref ref="logstash"/> |
| 83 | + </root> |
| 84 | + </springProfile> |
| 85 | + |
| 86 | +</configuration> |
0 commit comments