SpringBoot应用系列文章
序
本文主要讲怎么在SpringBoot里头配置输出到logstash,使用elk技术栈实时查看日志。
准备elk
详见
新建项目
新增依赖
net.logstash.logback logstash-logback-encoder 4.4
配置logback
log/logstash-%d{yyyy-MM-dd}.log
log实例
@SpringBootApplicationpublic 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/cat/workspace/elkdemo/log/logstash-2016-02-04.log
kibana查看
:5601/
TODO
刚才那个nc到logstash的是静态导入的,需要配置动态导入log,以便实时查看。