Spring Boot教程(三十五)整合elk(2)

2018-03-01 11:17:48来源:oschina作者:abbie265人点击

分享
配置、启动kibana

到kibana的安装目录:


./bin/kibana

默认配置即可。


访问localhost:5601,网页显示:


image.png


证明启动成功。


创建springboot工程

起步依赖如下:




org.springframework.boot
spring-boot-starter


org.springframework.boot
spring-boot-starter-logging




org.springframework.boot
spring-boot-starter-log4j
1.3.8.RELEASE


org.springframework.boot
spring-boot-starter-test
test

log4j的配置,/src/resources/log4j.properties如下:


log4j.rootLogger=INFO,console
# for package com.demo.elk, log would be sent to socket appender.
log4j.logger.com.forezp=DEBUG, socket
# appender socket
log4j.appender.socket=org.apache.log4j.net.SocketAppender
log4j.appender.socket.Port=4560
log4j.appender.socket.RemoteHost=localhost
log4j.appender.socket.layout=org.apache.log4j.PatternLayout
log4j.appender.socket.layout.ConversionPattern=%d [%-5p] [%l] %m%n
log4j.appender.socket.ReconnectionDelay=10000
# appender console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d [%-5p] [%l] %m%n

打印log测试:


@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootElkApplicationTests {
@Test
public void contextLoads() {
}
private Logger logger = Logger.getLogger(getClass());
@Test
public void test() throws Exception {
for(int i=0;i<100;i++) {
logger.info("输出info");
logger.debug("输出debug+skkkw嗡嗡嗡kw");
logger.error("输出error嗡嗡嗡我");
}
}}
源码来源

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台