logback接入logstash
Posted 老司机带你浪哦
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了logback接入logstash相关的知识,希望对你有一定的参考价值。
<springProperty scope="context" name="springAppName"
source="spring.application.name" />
<springProperty scope="context" name="logstash_url" source="LOGSTASH_URL" defaultValue="10.32.201.20:4560"
/>
<!-- ip_IS_UNDEFINED,无法获取到值 -->
<!--
<springProperty scope="context" name="ip" source="spring.cloud.client.ipAddress" />
-->
<appender name="LOGSTASH"
class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>${logstash_url}</destination>
<!-- 日志输出编码 -->
<encoder charset="UTF-8"
class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<mdc />
<timestamp>
<timeZone>UTC</timeZone>
</timestamp>
<version />
<message />
<loggerName />
<threadName />
<logLevel />
<!-- 包含4个属性 caller_class_name, caller_file_name, caller_line_number, caller_method_name, 前面两个其实不需要, 都是按照类名来区分, 已经有了 -->
<!-- <callerData /> -->
<pattern>
<pattern>
{
"method_name": "%method",
"line_number": "%line",
"service": "${springAppName}",
"env": "${spring.profiles.active}"
}
</pattern>
</pattern>
<stackTrace>
<throwableConverter
class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
<maxDepthPerThrowable>5</maxDepthPerThrowable>
<maxLength>4096</maxLength>
<rootCauseFirst>true</rootCauseFirst>
</throwableConverter>
</stackTrace>
</providers>
</encoder>
<includeCallerData>true</includeCallerData>
</appender>
<springProfile name="dev">
<root level="info">
<appender-ref ref="APP" />
<!-- STDOUT仅在本地打开,勿提交至服务端,避免将日志输出至tomcat日志文件 -->
<appender-ref ref="STDOUT" />
<appender-ref ref="LOGSTASH" />
</root>
</springProfile>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>6.3</version>
</dependency>
以上是关于logback接入logstash的主要内容,如果未能解决你的问题,请参考以下文章