SpringBoot应用之ELK
来自: https://segmentfault.com/a/1190000004416276
SpringBoot应用系列文章
序
本文主要讲怎么在SpringBoot里头配置输出到logstash,使用elk技术栈实时查看日志。
准备elk
新建项目
新增依赖
<dependency> <groupId>net.logstash.logback</groupId> <artifactId>logstash-logback-encoder</artifactId> <version>4.4</version> </dependency>
配置logback
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration> <configuration> <appender name="LOGSTASH" class="ch.qos.logback.core.rolling.RollingFileAppender"> <encoder class="net.logstash.logback.encoder.LogstashEncoder"> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>log/logstash-%d{yyyy-MM-dd}.log</fileNamePattern> </rollingPolicy> </appender> <root level="INFO"> <appender-ref ref="LOGSTASH" /> </root> </configuration>
log实例
@SpringBootApplication public class ElkdemoApplication implements CommandLineRunner{ private static final Logger logger = LoggerFactory.getLogger(ElkdemoApplication.class); public static void main(String[] args) { SpringApplication.run(ElkdemoApplication.class, args); } @Autowired LogDemoService logDemoService; @Override public void run(String... strings) throws Exception { while(true){ logDemoService.generateLog(); Thread.sleep(1000); logger.info("current thread:{},content:{}",Thread.currentThread().getName(), UUID.randomUUID().toString()); } } }
导入logstash
nc 192.168.99.100 5000 < /Users/patterncat/workspace/elkdemo/log/logstash-2016-02-04.log
kibana查看
http://192.168.99.100 :5601/
TODO
刚才那个nc到logstash的是静态导入的,需要配置动态导入log,以便实时查看。
本工程 github
参考
</div> 本文由用户 ozxw4146 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!