集成elk收集日志
This commit is contained in:
14
mall-demo/src/main/resources/logback-spring.xml
Normal file
14
mall-demo/src/main/resources/logback-spring.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE configuration>
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/base.xml"/>
|
||||
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
|
||||
<destination>localhost:4560</destination>
|
||||
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" />
|
||||
</appender>
|
||||
<root level="INFO">
|
||||
<appender-ref ref="LOGSTASH" />
|
||||
<appender-ref ref="CONSOLE" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
@@ -1,16 +1,31 @@
|
||||
package com.macro.mall;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.macro.mall.model.PmsProduct;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class MallDemoApplicationTests {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(MallDemoApplicationTests.class);
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLogStash() throws Exception {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
PmsProduct product = new PmsProduct();
|
||||
product.setId(1L);
|
||||
product.setName("小米手机");
|
||||
product.setBrandName("小米");
|
||||
logger.info(mapper.writeValueAsString(product));
|
||||
logger.error(mapper.writeValueAsString(product));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user