logback.xml
dependency:
implementation 'net.logstash.logback:logstash-logback-encoder:7.2'
logback.xml file:
<!--<configuration debug="true">-->
<!-- <property resource="application.yaml"/>-->
<!-- <springProperty name="application_name" source="spring.application.name"/>-->
<!-- <springProperty name="application_env" source="spring.profiles.active"/>-->
<!-- <!– <springProperty scope="context" name="REPLICA_HOSTNAME" source="REPLICA_HOSTNAME" />-->
<!-- –>-->
<!-- <variable name="LOGSTASH_HOST" value="${LOGSTASH_HOST}"/>-->
<!-- <variable name="LOGSTASH_PORT" value="${LOGSTASH_PORT:-31111}"/>-->
<!-- <variable name="REPLICA_HOSTNAME" value="${REPLICA_HOSTNAME}"/>-->
<!-- <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"/>-->
<!-- <include resource="org/springframework/boot/logging/logback/base.xml"/>-->
<!-- <springProfile name="!local">-->
<!-- <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">-->
<!-- <destination>${LOGSTASH_HOST}:${LOGSTASH_PORT}</destination>-->
<!-- <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">-->
<!-- <providers>-->
<!-- <timestamp/>-->
<!-- <version/>-->
<!-- <loggerName/>-->
<!-- <pattern>-->
<!-- <pattern>-->
<!-- { "level": "%level" , "app_name" : "${application_name}", "x-trace-id" : "%X{X-Trace-ID}",-->
<!-- "thread": "%thread", "message": "%message", "environment": "${application_env}", "replica" :-->
<!-- "${REPLICA_HOSTNAME}" }-->
<!-- </pattern>-->
<!-- </pattern>-->
<!-- </providers>-->
<!-- </encoder>-->
<!-- </appender>-->
<!-- <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">-->
<!-- <encoder>-->
<!-- <pattern>%blue(%d{HH:mm:ss.SSS}[%thread]) %green(%-5level %logger{36}) - %msg%n</pattern>-->
<!-- </encoder>-->
<!-- </appender>-->
<!-- <root level="info">-->
<!-- <appender-ref ref="Console"/>-->
<!-- <appender-ref ref="LOGSTASH"/>-->
<!-- </root>-->
<!-- </springProfile>-->
<!--</configuration>-->
<configuration debug="true">
<property resource="application.yaml"/>
<springProperty name="application_name" source="spring.application.name"/>
<springProperty name="application_env" source="spring.profiles.active"/>
<variable name="LOGSTASH_HOST" value="${LOGSTASH_HOST:-localhost}"/>
<variable name="LOGSTASH_PORT" value="${LOGSTASH_PORT:-31111}"/>
<variable name="REPLICA_HOSTNAME" value="${REPLICA_HOSTNAME:-unknown}"/>
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener"/>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<springProfile name="!local">
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>${LOGSTASH_HOST}:${LOGSTASH_PORT}</destination>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp/>
<version/>
<loggerName/>
<pattern>
<pattern>
{ "level": "%level" , "app_name" : "${application_name}", "x-trace-id" : "%X{X-Trace-ID}",
"thread": "%thread", "message": "%message", "environment": "${application_env}", "replica" :
"${REPLICA_HOSTNAME}" }
</pattern>
</pattern>
</providers>
</encoder>
</appender>
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%blue(%d{HH:mm:ss.SSS}[%thread]) %green(%-5level %logger{36}) - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="Console"/>
<appender-ref ref="LOGSTASH"/>
</root>
</springProfile>
</configuration>
Комментарии
Отправить комментарий