springboot整合logback集成elk实现日志的汇总分析统计和检索功能

Posted xiaoyao-001

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot整合logback集成elk实现日志的汇总分析统计和检索功能相关的知识,希望对你有一定的参考价值。

  在Spring Boot当中,默认使用logback进行log操作。logback支持将日志数据通过提供IP地址、端口号,以Socket的方式远程发送。在Spring Boot中,通常使用logback-spring.xml来进行logback配置。

首先、创建一个elk的springboot项目,然后先对logback进行配置,配置各项的详细说明可以去看http://aub.iteye.com/blog/1101222,说的很详细。也多参考一下别人关于日志的描述https://www.cnblogs.com/mr-yang-localhost/p/8284317.html

logback代码

技术分享图片
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!-- 设置配置文件如果改动自动加载,监测是否修改时间间隔为60s,不打印logback内部日志信息 -->
 3 <configuration scan="true" scanPeriod="60 seconds" debug="true">
 4 <!--设置上下文名称  -->
 5     <property name="appName" value="elk"/>
 6     <contextName>${appName}</contextName>
 7     <!-- <timestamp key="" datePattern=""/> -->
 8     <!-- 存放日志地址 -->
 9     <property name="log_home" value="loghome"/>
10     <!-- 控制台输出 -->
11     <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
12         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
13         <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
14             <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} {%thread} %-5level %logger{50} - %msg%n</pattern>
15         </encoder>
16     </appender>
17      <appender name="FILE" class="ch.qos.logback.core.FileAppender">
18         <file>./${log_home}/elk.log</file> 
19         <Encoding>UTF-8</Encoding>   
20         <rollingPolicy class="ch.qos.logback.core.rolling.RollingPolicy">
21         日志文件输出的文件名
22             <FileNamePattern>${log_home}/elk.log.%d{yyyy-MM-dd}.log</FileNamePattern>
23             日志保留30天
24             <MaxHistory>30</MaxHistory>
25         </rollingPolicy>
26         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
27          格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 
28             <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>   
29         </encoder>
30         <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
31          <MaxFileSize>10MB</MaxFileSize>
32        </triggeringPolicy>
33     </appender>
34         <!--myibatis log configure--> 
35     <logger name="com.apache.ibatis" level="TRACE"/>
36     <logger name="java.sql.Connection" level="DEBUG"/>
37     <logger name="java.sql.Statement" level="DEBUG"/>
38     <logger name="java.sql.PreparedStatement" level="DEBUG"/>
39     
40     <!-- 日志输出级别 -->
41     <root level="INFO">
42         <appender-ref ref="STDOUT" />
43         <appender-ref ref="FILE" />
44     </root> 
45    <!--  
46     日志异步到数据库  
47     <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
48         日志异步到数据库 
49         <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
50            连接池 
51            <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
52               <driverClass>com.mysql.jdbc.Driver</driverClass>
53               <url>jdbc:mysql://127.0.0.1:3306/databaseName</url>
54               <user>root</user>
55               <password>root</password>
56             </dataSource>
57         </connectionSource>
58   </appender> -->
59 </configuration>
View Code

yml

 1 logging:
 2   config: classpath:logback-spring.xml
 3 spring:
 4   datasource:
 5     driver-class-name: com.mysql.jdbc.Driver
 6     url: jdbc:mysql://localhost:3306/test
 7     username: root
 8     password: 123456
 9 
10 
11 
12 
13 
14 注意:加载logback的配置文件一定要有classpath: 否则报错

运行测试类

技术分享图片
 1 package com.zxy.demo;
 2 
 3 import org.junit.Test;
 4 import org.junit.runner.RunWith;
 5 import org.slf4j.Logger;
 6 import org.slf4j.LoggerFactory;
 7 import org.springframework.boot.test.context.SpringBootTest;
 8 import org.springframework.test.context.junit4.SpringRunner;
 9 
10 @RunWith(SpringRunner.class)
11 @SpringBootTest
12 public class ElkApplicationTests {
13     private Logger logger = LoggerFactory.getLogger(this.getClass());
14 
15     @Test
16     public void contextLoads() {
17     }
18     @Test
19     public void testLog() {
20         logger.info("message:this is first logger!");
21     }
22 }
View Code

效果

技术分享图片
  1 11:57:36,907 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [file:/D:/worksheet/elk/target/classes/logback-spring.xml] 
  2 11:57:36,909 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 1 minutes
  3 11:57:36,913 |-INFO in ch.qos.logback.classic.joran.action.ContextNameAction - Setting logger context name as [elk]
  4 11:57:36,913 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
  5 11:57:36,914 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
  6 11:57:36,933 |-WARN in Logger[org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator] - No appenders present in context [elk] for logger [org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator].
  7 11:57:36,942 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
  8 11:57:36,944 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE]
  9 11:57:36,945 |-ERROR in [email protected]:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
 10 11:57:36,945 |-ERROR in [email protected]:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
 11 11:57:36,946 |-ERROR in [email protected]:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
 12 11:57:36,946 |-ERROR in [email protected]:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
 13 11:57:36,947 |-ERROR in [email protected]:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
 14 11:57:36,947 |-ERROR in [email protected]:23 - no applicable action for [MaxFileSize], current ElementPath  is [[configuration][appender][triggeringPolicy][MaxFileSize]]
 15 11:57:36,947 |-INFO in ch.qos.logback.core.FileAppender[FILE] - File property is set to [./loghome/elk.log]
 16 11:57:36,950 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.apache.ibatis] to TRACE
 17 11:57:36,950 |-INFO in [email protected] - Propagating TRACE level on Logger[com.apache.ibatis] onto the JUL framework
 18 11:57:36,950 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [java.sql.Connection] to DEBUG
 19 11:57:36,950 |-INFO in [email protected] - Propagating DEBUG level on Logger[java.sql.Connection] onto the JUL framework
 20 11:57:36,950 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [java.sql.Statement] to DEBUG
 21 11:57:36,950 |-INFO in [email protected] - Propagating DEBUG level on Logger[java.sql.Statement] onto the JUL framework
 22 11:57:36,951 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [java.sql.PreparedStatement] to DEBUG
 23 11:57:36,951 |-INFO in [email protected] - Propagating DEBUG level on Logger[java.sql.PreparedStatement] onto the JUL framework
 24 11:57:36,951 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
 25 11:57:36,951 |-INFO in [email protected] - Propagating INFO level on Logger[ROOT] onto the JUL framework
 26 11:57:36,951 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
 27 11:57:36,952 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to Logger[ROOT]
 28 11:57:36,952 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
 29 11:57:36,952 |-INFO in org.s[email protected]479d31f3 - Registering current configuration as safe fallback point
 30 Logging system failed to initialize using configuration from ‘classpath:logback-spring.xml‘
 31 java.lang.IllegalStateException: Logback configuration error detected: 
 32 ERROR in [email protected]:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
 33 ERROR in [email protected]:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
 34 ERROR in ch.qos.logback.core.joran.spi[email protected]:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
 35 ERROR in [email protected]:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
 36 ERROR in [email protected]:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
 37 ERROR in [email protected]:23 - no applicable action for [MaxFileSize], current ElementPath  is [[configuration][appender][triggeringPolicy][MaxFileSize]]
 38     at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
 39     at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:67)
 40     at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)
 41     at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:117)
 42     at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:269)
 43     at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:237)
 44     at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200)
 45     at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:173)
 46     at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
 47     at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
 48     at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
 49     at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
 50     at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
 51     at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
 52     at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:364)
 53     at org.springframework.boot.SpringApplication.run(SpringApplication.java:323)
 54     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277)
 55     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265)
 56     at com.zxy.demo.ElkApplication.main(ElkApplication.java:11)
 57 2018-10-01 11:57:37.464 {main} ERROR org.springframework.boot.SpringApplication - Application run failed
 58 java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected: 
 59 ERROR in [email protected]:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
 60 ERROR in [email protected]:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
 61 ERROR in [email protected]:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
 62 ERROR in [email protected]:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
 63 ERROR in [email protected]:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
 64 ERROR in [email protected]:23 - no applicable action for [MaxFileSize], current ElementPath  is [[configuration][appender][triggeringPolicy][MaxFileSize]]
 65     at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:276)
 66     at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:237)
 67     at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200)
 68     at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:173)
 69     at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
 70     at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
 71     at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
 72     at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
 73     at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
 74     at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
 75     at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:364)
 76     at org.springframework.boot.SpringApplication.run(SpringApplication.java:323)
 77     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277)
 78     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265)
 79     at com.zxy.demo.ElkApplication.main(ElkApplication.java:11)
 80 Caused by: java.lang.IllegalStateException: Logback configuration error detected: 
 81 ERROR in [email protected]:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
 82 ERROR in [email protected]:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
 83 ERROR in [email protected]:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
 84 ERROR in [email protected]:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
 85 ERROR in [email protected]:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
 86 ERROR in [email protected]:23 - no applicable action for [MaxFileSize], current ElementPath  is [[configuration][appender][triggeringPolicy][MaxFileSize]]
 87     at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
 88     at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:67)
 89     at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)
 90     at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:117)
 91     at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:269)
 92     ... 14 common frames omitted
 93 Exception in thread "main" java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected: 
 94 ERROR in [email protected]:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
 95 ERROR in [email protected]:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
 96 ERROR in [email protected]:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
 97 ERROR in [email protected]:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
 98 ERROR in [email protected]:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
 99 ERROR in [email protected]:23 - no applicable action for [MaxFileSize], current ElementPath  is [[configuration][appender][triggeringPolicy][MaxFileSize]]
100     at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:276)
101     at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:237)
102     at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:200)
103     at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:173)
104     at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
105     at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
106     at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
107     at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
108     at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
109     at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
110     at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:364)
111     at org.springframework.boot.SpringApplication.run(SpringApplication.java:323)
112     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277)
113     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265)
114     at com.zxy.demo.ElkApplication.main(ElkApplication.java:11)
115 Caused by: java.lang.IllegalStateException: Logback configuration error detected: 
116 ERROR in [email protected]:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
117 ERROR in [email protected]:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
118 ERROR in [email protected]:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
119 ERROR in [email protected]:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
120 ERROR in [email protected]:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
121 ERROR in [email protected]:23 - no applicable action for [MaxFileSize], current ElementPath  is [[configuration][appender][triggeringPolicy][MaxFileSize]]
122     at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
123     at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:67)
124     at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)
125     at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:117)
126     at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:269)
127     ... 14 more
View Code

报错是因为引用的apender选择错误,更改相应代码

logback代码更改后:

技术分享图片
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!-- 设置配置文件如果改动自动加载,监测是否修改时间间隔为60s,不打印logback内部日志信息 -->
 3 <configuration scan="true" scanPeriod="60 seconds" debug="true">
 4 <!--设置上下文名称  -->
 5     <property name="appName" value="elk"/>
 6     <contextName>${appName}</contextName>
 7     <!-- <timestamp key="" datePattern=""/> -->
 8     <!-- 存放日志地址 -->
 9     <property name="log_home" value="d:/"/>
10     <!-- 控制台输出 -->
11     <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
12         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
13         <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
14             <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} {%thread} %-5level %logger{50} =======> %msg%n</pattern>
15         </encoder>
16     </appender>
17     <!-- 滚动记录日志 -->
18      <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">  <!-- 类要引用正确ch.qos.logback.core.FileAppender -->
19         <file>${log_home}/elk.log</file>  <!-- 引用ch.qos.logback.core.FileAppender需要的属性,这里不需要-->
20     <!--     <append>true</append> -->
21       <!--   <Encoding>UTF-8</Encoding>   1.17版本后不能用,去掉 -->
22         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 不是ch.qos.logback.core.rolling.RollingPolicy -->
23         <!-- 日志文件输出的文件名 -->
24             <fileNamePattern>${log_home}/%d{yyyy-MM-dd}/error-log.log</fileNamePattern>
25             <!-- 日志保留30天 -->
26             <maxHistory>30</maxHistory>
27         </rollingPolicy>
28         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
29         <!--  格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符  -->
30             <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} {%thread} %-5level %logger{50} =======> %msg%n</pattern>   
31         </encoder>
32         <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
33          <MaxFileSize>10MB</MaxFileSize>
34        </triggeringPolicy>
35     </appender>
36         <!--myibatis log configure--> 
37     <logger name="com.apache.ibatis" level="TRACE"/>
38     <logger name="java.sql.Connection" level="DEBUG"/>
39     <logger name="java.sql.Statement" level="DEBUG"/>
40     <logger name="java.sql.PreparedStatement" level="DEBUG"/>
41     
42     <!-- 日志输出级别 -->
43     <root level="INFO">
44         <appender-ref ref="STDOUT" />
45         <appender-ref ref="FILE" />
46     </root> 
47    <!--  
48     日志异步到数据库  
49     <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
50         日志异步到数据库 
51         <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
52            连接池 
53            <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
54               <driverClass>com.mysql.jdbc.Driver</driverClass>
55               <url>jdbc:mysql://127.0.0.1:3306/databaseName</url>
56               <user>root</user>
57               <password>root</password>
58             </dataSource>
59         </connectionSource>
60   </appender> -->
61 </configuration>
View Code

再次运行看一下效果

技术分享图片
 1 13:13:24.339 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.zxy.demo.ElkApplicationTests]
 2 13:13:24.359 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
 3 13:13:24.370 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
 4 13:13:24.392 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.zxy.demo.ElkApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
 5 13:13:24.409 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.zxy.demo.ElkApplicationTests], using SpringBootContextLoader
 6 13:13:24.416 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.zxy.demo.ElkApplicationTests]: class path resource [com/zxy/demo/ElkApplicationTests-context.xml] does not exist
 7 13:13:24.417 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.zxy.demo.ElkApplicationTests]: class path resource [com/zxy/demo/ElkApplicationTestsContext.groovy] does not exist
 8 13:13:24.417 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.zxy.demo.ElkApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
 9 13:13:24.418 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.zxy.demo.ElkApplicationTests]: ElkApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
10 13:13:24.479 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an ‘annotation declaring class‘ for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.zxy.demo.ElkApplicationTests]
11 13:13:24.492 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding PropertySource ‘systemProperties‘ with lowest search precedence
12 13:13:24.493 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding PropertySource ‘systemEnvironment‘ with lowest search precedence
13 13:13:24.493 [main] DEBUG org.springframework.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [[email protected] {name=‘systemProperties‘, properties={java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=D:javajava1.8jre1.8in, java.vm.version=25.161-b12, java.vm.vendor=Oracle Corporation, java.vendor.url=http://java.oracle.com/, path.separator=;, java.vm.name=Java HotSpot(TM) 64-Bit Server VM, file.encoding.pkg=sun.io, user.country=CN, user.script=, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=, java.vm.specification.name=Java Virtual Machine Specification, user.dir=D:worksheetelk, java.runtime.version=1.8.0_161-b12, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=D:javajava1.8jre1.8libendorsed, os.arch=amd64, java.io.tmpdir=C:UserslitanAppDataLocalTemp, line.separator=
14 , java.vm.specification.vendor=Oracle Corporation, user.variant=, os.name=Windows 10, sun.jnu.encoding=GBK, java.library.path=D:javajava1.8jre1.8in;C:WINDOWSSunJavain;C:WINDOWSsystem32;C:WINDOWS;C:ProgramDataOracleJavajavapath;D:javaoracleproduct11.2.0dbhome_1in;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)Common Fileslenovoeasyplussdkin;C:Program Files (x86)ATI TechnologiesATI.ACECore-Static;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5Doctrine extensions for php;D:javajava1.8jdk1.8in;JAVA_HOME%jrein;D:java_reviewapache-tomcat-7.0.67in;D:我的软件;办公软;svnServerin;%ma;en_home%in;D:我的软件数据库putty;C:Pro;ram FilesIntelWiFiin;C:Program FilesCommon FilesIntelWirelessCommon;";D:我的软件专业软件zookeeperzookeeper-3.4.9/bin; D:我的软件专业软件zookeeperzookeeper-3.4.9/conf";D:javajava1.8jdk1.8in;C:Program FilesTortoiseGitin;C:Program FilesGitcmd;C:WINDOWSSystem32OpenSSH;D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9in;D:protobufcin;C:UserslitanAppDataLocalMicrosoftWindowsApps;D:java软件安装资源汇总2017-6-25apache-maven-3.3.9-binapache-maven-3.3.9in;;., java.specification.name=Java Platform API Specification, java.class.version=52.0, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, os.version=10.0, user.home=C:Userslitan, user.timezone=Asia/Shanghai, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=UTF-8, java.specification.version=1.8, java.class.path=D:worksheetelk	arget	est-classes;D:worksheetelk	argetclasses;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-web2.0.5.RELEASEspring-boot-starter-web-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter2.0.5.RELEASEspring-boot-starter-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot2.0.5.RELEASEspring-boot-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-autoconfigure2.0.5.RELEASEspring-boot-autoconfigure-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-logging2.0.5.RELEASEspring-boot-starter-logging-2.0.5.RELEASE.jar;C:Userslitan.m2
epositorychqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;C:Userslitan.m2
epositorychqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;C:Userslitan.m2
epositoryorgapachelogginglog4jlog4j-to-slf4j2.10.0log4j-to-slf4j-2.10.0.jar;C:Userslitan.m2
epositoryorgapachelogginglog4jlog4j-api2.10.0log4j-api-2.10.0.jar;C:Userslitan.m2
epositoryorgslf4jjul-to-slf4j1.7.25jul-to-slf4j-1.7.25.jar;C:Userslitan.m2
epositoryjavaxannotationjavax.annotation-api1.3.2javax.annotation-api-1.3.2.jar;C:Userslitan.m2
epositoryorgyamlsnakeyaml1.19snakeyaml-1.19.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-json2.0.5.RELEASEspring-boot-starter-json-2.0.5.RELEASE.jar;C:Userslitan.m2
epositorycomfasterxmljacksoncorejackson-databind2.9.6jackson-databind-2.9.6.jar;C:Userslitan.m2
epositorycomfasterxmljacksoncorejackson-annotations2.9.0jackson-annotations-2.9.0.jar;C:Userslitan.m2
epositorycomfasterxmljacksoncorejackson-core2.9.6jackson-core-2.9.6.jar;C:Userslitan.m2
epositorycomfasterxmljacksondatatypejackson-datatype-jdk82.9.6jackson-datatype-jdk8-2.9.6.jar;C:Userslitan.m2
epositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.9.6jackson-datatype-jsr310-2.9.6.jar;C:Userslitan.m2
epositorycomfasterxmljacksonmodulejackson-module-parameter-names2.9.6jackson-module-parameter-names-2.9.6.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-tomcat2.0.5.RELEASEspring-boot-starter-tomcat-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgapache	omcatembed	omcat-embed-core8.5.34	omcat-embed-core-8.5.34.jar;C:Userslitan.m2
epositoryorgapache	omcatembed	omcat-embed-el8.5.34	omcat-embed-el-8.5.34.jar;C:Userslitan.m2
epositoryorgapache	omcatembed	omcat-embed-websocket8.5.34	omcat-embed-websocket-8.5.34.jar;C:Userslitan.m2
epositoryorghibernatevalidatorhibernate-validator6.0.12.Finalhibernate-validator-6.0.12.Final.jar;C:Userslitan.m2
epositoryjavaxvalidationvalidation-api2.0.1.Finalvalidation-api-2.0.1.Final.jar;C:Userslitan.m2
epositoryorgjbossloggingjboss-logging3.3.2.Finaljboss-logging-3.3.2.Final.jar;C:Userslitan.m2
epositorycomfasterxmlclassmate1.3.4classmate-1.3.4.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-web5.0.9.RELEASEspring-web-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-beans5.0.9.RELEASEspring-beans-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-webmvc5.0.9.RELEASEspring-webmvc-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-aop5.0.9.RELEASEspring-aop-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-context5.0.9.RELEASEspring-context-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-expression5.0.9.RELEASEspring-expression-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgmybatisspringootmybatis-spring-boot-starter1.3.2mybatis-spring-boot-starter-1.3.2.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-jdbc2.0.5.RELEASEspring-boot-starter-jdbc-2.0.5.RELEASE.jar;C:Userslitan.m2
epositorycomzaxxerHikariCP2.7.9HikariCP-2.7.9.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-jdbc5.0.9.RELEASEspring-jdbc-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-tx5.0.9.RELEASEspring-tx-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgmybatisspringootmybatis-spring-boot-autoconfigure1.3.2mybatis-spring-boot-autoconfigure-1.3.2.jar;C:Userslitan.m2
epositoryorgmybatismybatis3.4.6mybatis-3.4.6.jar;C:Userslitan.m2
epositoryorgmybatismybatis-spring1.3.2mybatis-spring-1.3.2.jar;C:Userslitan.m2
epositorymysqlmysql-connector-java5.1.47mysql-connector-java-5.1.47.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-test2.0.5.RELEASEspring-boot-starter-test-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-test2.0.5.RELEASEspring-boot-test-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-test-autoconfigure2.0.5.RELEASEspring-boot-test-autoconfigure-2.0.5.RELEASE.jar;C:Userslitan.m2
epositorycomjaywayjsonpathjson-path2.4.0json-path-2.4.0.jar;C:Userslitan.m2
epository
etminidevjson-smart2.3json-smart-2.3.jar;C:Userslitan.m2
epository
etminidevaccessors-smart1.2accessors-smart-1.2.jar;C:Userslitan.m2
epositoryorgow2asmasm5.0.4asm-5.0.4.jar;C:Userslitan.m2
epositoryorgslf4jslf4j-api1.7.25slf4j-api-1.7.25.jar;C:Userslitan.m2
epositoryjunitjunit4.12junit-4.12.jar;C:Userslitan.m2
epositoryorgassertjassertj-core3.9.1assertj-core-3.9.1.jar;C:Userslitan.m2
epositoryorgmockitomockito-core2.15.0mockito-core-2.15.0.jar;C:Userslitan.m2
epository
etytebuddyyte-buddy1.7.11yte-buddy-1.7.11.jar;C:Userslitan.m2
epository
etytebuddyyte-buddy-agent1.7.11yte-buddy-agent-1.7.11.jar;C:Userslitan.m2
epositoryorgobjenesisobjenesis2.6objenesis-2.6.jar;C:Userslitan.m2
epositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;C:Userslitan.m2
epositoryorghamcresthamcrest-library1.3hamcrest-library-1.3.jar;C:Userslitan.m2
epositoryorgskyscreamerjsonassert1.5.0jsonassert-1.5.0.jar;C:Userslitan.m2
epositorycomvaadinexternalgoogleandroid-json.0.20131108.vaadin1android-json-0.0.20131108.vaadin1.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-core5.0.9.RELEASEspring-core-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-jcl5.0.9.RELEASEspring-jcl-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-test5.0.9.RELEASEspring-test-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgxmlunitxmlunit-core2.5.1xmlunit-core-2.5.1.jar;D:javaDevlepTooleclipse4.8eclipseconfigurationorg.eclipse.osgi416.cp;D:javaDevlepTooleclipse4.8eclipseconfigurationorg.eclipse.osgi415.cp, user.name=litan, java.vm.specification.version=1.8, sun.java.command=org.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 52767 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -test com.zxy.demo.ElkApplicationTests:testLog, java.home=D:javajava1.8jre1.8, sun.arch.data.model=64, user.language=zh, java.specification.vendor=Oracle Corporation, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, java.version=1.8.0_161, java.ext.dirs=D:javajava1.8jre1.8libext;C:WINDOWSSunJavalibext, sun.boot.class.path=D:javajava1.8jre1.8lib
esources.jar;D:javajava1.8jre1.8lib
t.jar;D:javajava1.8jre1.8libsunrsasign.jar;D:javajava1.8jre1.8libjsse.jar;D:javajava1.8jre1.8libjce.jar;D:javajava1.8jre1.8libcharsets.jar;D:javajava1.8jre1.8libjfr.jar;D:javajava1.8jre1.8classes, java.vendor=Oracle Corporation, file.separator=, java.vendor.url.bug=http://bugreport.sun.com/bugreport/, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, sun.cpu.isalist=amd64}}, [email protected] {name=‘systemEnvironment‘, properties={configsetroot=C:WINDOWSConfigSetRoot, USERDOMAIN_ROAMINGPROFILE=LITAN, PROCESSOR_LEVEL=6, SESSIONNAME=Console, ALLUSERSPROFILE=C:ProgramData, PROCESSOR_ARCHITECTURE=AMD64, PSModulePath=C:Program FilesWindowsPowerShellModules;C:WINDOWSsystem32WindowsPowerShellv1.0Modules;D:我的软件办公软件svnServerPowerShellModules, SystemDrive=C:, MAVEN_HOME=D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9, USERNAME=litan, ProgramFiles(x86)=C:Program Files (x86), VISUALSVN_SERVER=D:我的软件办公软件svnServer, FPS_BROWSER_USER_PROFILE_STRING=Default, PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC, DriverData=C:WindowsSystem32DriversDriverData, ProgramData=C:ProgramData, ProgramW6432=C:Program Files, HOMEPATH=Userslitan, PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 61 Stepping 4, GenuineIntel, ProgramFiles=C:Program Files, PUBLIC=C:UsersPublic, windir=C:WINDOWS, =::=::, ZOOKEEPER_HOME=D:我的软件专业软件zookeeperzookeeper-3.4.9, LOCALAPPDATA=C:UserslitanAppDataLocal, USERDOMAIN=LITAN, FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer, LOGONSERVER=\\LITAN, JAVA_HOME=D:javajava1.8jdk1.8, ERLANG_HOME=D:	opbandsoftRabbitMQerl7.1, OneDrive=C:UserslitanOneDrive, =C:=C:, APPDATA=C:UserslitanAppDataRoaming, CommonProgramFiles=C:Program FilesCommon Files, Path=C:ProgramDataOracleJavajavapath;D:javaoracleproduct11.2.0dbhome_1in;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)Common Fileslenovoeasyplussdkin;C:Program Files (x86)ATI TechnologiesATI.ACECore-Static;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5Doctrine extensions for PHP;D:javajava1.8jdk1.8in;JAVA_HOME%jrein;D:java_reviewapache-tomcat-7.0.67in;D:我的软件;办公软;svnServerin;%ma;en_home%in;D:我的软件数据库putty;C:Pro;ram FilesIntelWiFiin;C:Program FilesCommon FilesIntelWirelessCommon;";D:我的软件专业软件zookeeperzookeeper-3.4.9/bin; D:我的软件专业软件zookeeperzookeeper-3.4.9/conf";D:javajava1.8jdk1.8in;C:Program FilesTortoiseGitin;C:Program FilesGitcmd;C:WINDOWSSystem32OpenSSH;D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9in;D:protobufcin;C:UserslitanAppDataLocalMicrosoftWindowsApps;D:java软件安装资源汇总2017-6-25apache-maven-3.3.9-binapache-maven-3.3.9in;, OS=Windows_NT, COMPUTERNAME=LITAN, CATALINA_HOME=D:java_reviewapache-tomcat-7.0.67, PROCESSOR_REVISION=3d04, CLASSPATH=.;D:javajava1.8jdk1.8lib;D:javajava1.8jdk1.8lib	ools.jar, CommonProgramW6432=C:Program FilesCommon Files, ComSpec=C:WINDOWSsystem32cmd.exe, SystemRoot=C:WINDOWS, TEMP=C:UserslitanAppDataLocalTemp, HOMEDRIVE=C:, USERPROFILE=C:Userslitan, TMP=C:UserslitanAppDataLocalTemp, easyplussdk="C:Program Files (x86)Common Fileslenovoeasyplussdkin", CommonProgramFiles(x86)=C:Program Files (x86)Common Files, NUMBER_OF_PROCESSORS=4}}]
15 13:13:24.513 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved classpath location [com/zxy/demo/] to resources [URL [file:/D:/worksheet/elk/target/test-classes/com/zxy/demo/], URL [file:/D:/worksheet/elk/target/classes/com/zxy/demo/]]
16 13:13:24.514 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Looking for matching resources in directory tree [D:worksheetelk	arget	est-classescomzxydemo]
17 13:13:24.514 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Searching directory [D:worksheetelk	arget	est-classescomzxydemo] for files matching pattern [D:/worksheet/elk/target/test-classes/com/zxy/demo/*.class]
18 13:13:24.518 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Looking for matching resources in directory tree [D:worksheetelk	argetclassescomzxydemo]
19 13:13:24.518 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Searching directory [D:worksheetelk	argetclassescomzxydemo] for files matching pattern [D:/worksheet/elk/target/classes/com/zxy/demo/*.class]
20 13:13:24.519 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved location pattern [classpath*:com/zxy/demo/*.class] to resources [file [D:worksheetelk	arget	est-classescomzxydemoElkApplicationTests.class], file [D:worksheetelk	argetclassescomzxydemoElkApplication.class]]
21 13:13:24.585 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [D:worksheetelk	argetclassescomzxydemoElkApplication.class]
22 13:13:24.587 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.zxy.demo.ElkApplication for test class com.zxy.demo.ElkApplicationTests
23 13:13:24.772 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.zxy.demo.ElkApplicationTests]: using defaults.
24 13:13:24.774 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
25 13:13:24.797 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [or[email protected]79924b, org.springframework.test[email protected]7b9a4292, org.spri[email protected]4a94ee4, org.springframework.boot.test.a[email protected]4cc451f2, org.springfra[email protected]6379eb, org.springframew[email protected]294425a7, org.sp[email protected]67d48005, org.springf[email protected]9f116cc, org.springframework[email protected]12468a38, org.springframework.boot.test.autoconfi[email protected]1aa7ecca, org.springframework.boot.test.autoconfi[email protected]59309333, org.springframework.boo[email protected]5876a9af]
26 13:13:24.799 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.zxy.demo.ElkApplicationTests]
27 13:13:24.799 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.zxy.demo.ElkApplicationTests]
28 13:13:24.801 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.zxy.demo.ElkApplicationTests]
29 13:13:24.801 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.zxy.demo.ElkApplicationTests]
30 13:13:24.821 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.zxy.demo.ElkApplicationTests]
31 13:13:24.821 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.zxy.demo.ElkApplicationTests]
32 13:13:24.823 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.zxy.demo.ElkApplicationTests]
33 13:13:24.823 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.zxy.demo.ElkApplicationTests]
34 13:13:24.824 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.zxy.demo.ElkApplicationTests]
35 13:13:24.825 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.zxy.demo.ElkApplicationTests]
36 13:13:24.834 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [[email protected] testClass = ElkApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [[email protected] testClass = ElkApplicationTests, locations = ‘{}‘, classes = ‘{class com.zxy.demo.ElkApplication}‘, contextInitializerClasses = ‘[]‘, activeProfiles = ‘{}‘, propertySourceLocations = ‘{}‘, propertySourceProperties = ‘{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}‘, contextCustomizers = set[org.springfr[email protected]15d0c81b, org.springframework.boot.test.json.DuplicateJsonObje[email protected]17579e0f, org.[email protected]0, org.springf[email protected]7a765367, org.springframework.boot[email protected]0, org.springframework.boot.test.autocon[email protected]3234e239], resourceBasePath = ‘src/main/webapp‘, contextLoader = ‘org.springframework.boot.test.context.SpringBootContextLoader‘, parent = [null]], attributes = map[‘org.springframework.test.context.web.ServletTestExecutionListener.activateListener‘ -> true]], class annotated with @DirtiesContext [false] with mode [null].
37 13:13:24.835 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.zxy.demo.ElkApplicationTests]
38 13:13:24.835 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.zxy.demo.ElkApplicationTests]
39 13:13:24.866 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding PropertySource ‘systemProperties‘ with lowest search precedence
40 13:13:24.866 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding PropertySource ‘systemEnvironment‘ with lowest search precedence
41 13:13:24.867 [main] DEBUG org.springframework.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [[email protected] {name=‘systemProperties‘, properties={java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=D:javajava1.8jre1.8in, java.vm.version=25.161-b12, java.vm.vendor=Oracle Corporation, java.vendor.url=http://java.oracle.com/, path.separator=;, java.vm.name=Java HotSpot(TM) 64-Bit Server VM, file.encoding.pkg=sun.io, user.country=CN, user.script=, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=, java.vm.specification.name=Java Virtual Machine Specification, user.dir=D:worksheetelk, java.runtime.version=1.8.0_161-b12, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=D:javajava1.8jre1.8libendorsed, os.arch=amd64, java.io.tmpdir=C:UserslitanAppDataLocalTemp, line.separator=
42 , java.vm.specification.vendor=Oracle Corporation, user.variant=, os.name=Windows 10, sun.jnu.encoding=GBK, java.library.path=D:javajava1.8jre1.8in;C:WINDOWSSunJavain;C:WINDOWSsystem32;C:WINDOWS;C:ProgramDataOracleJavajavapath;D:javaoracleproduct11.2.0dbhome_1in;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)Common Fileslenovoeasyplussdkin;C:Program Files (x86)ATI TechnologiesATI.ACECore-Static;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5Doctrine extensions for PHP;D:javajava1.8jdk1.8in;JAVA_HOME%jrein;D:java_reviewapache-tomcat-7.0.67in;D:我的软件;办公软;svnServerin;%ma;en_home%in;D:我的软件数据库putty;C:Pro;ram FilesIntelWiFiin;C:Program FilesCommon FilesIntelWirelessCommon;";D:我的软件专业软件zookeeperzookeeper-3.4.9/bin; D:我的软件专业软件zookeeperzookeeper-3.4.9/conf";D:javajava1.8jdk1.8in;C:Program FilesTortoiseGitin;C:Program FilesGitcmd;C:WINDOWSSystem32OpenSSH;D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9in;D:protobufcin;C:UserslitanAppDataLocalMicrosoftWindowsApps;D:java软件安装资源汇总2017-6-25apache-maven-3.3.9-binapache-maven-3.3.9in;;., java.specification.name=Java Platform API Specification, java.class.version=52.0, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, os.version=10.0, user.home=C:Userslitan, user.timezone=Asia/Shanghai, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=UTF-8, java.specification.version=1.8, java.class.path=D:worksheetelk	arget	est-classes;D:worksheetelk	argetclasses;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-web2.0.5.RELEASEspring-boot-starter-web-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter2.0.5.RELEASEspring-boot-starter-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot2.0.5.RELEASEspring-boot-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-autoconfigure2.0.5.RELEASEspring-boot-autoconfigure-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-logging2.0.5.RELEASEspring-boot-starter-logging-2.0.5.RELEASE.jar;C:Userslitan.m2
epositorychqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;C:Userslitan.m2
epositorychqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;C:Userslitan.m2
epositoryorgapachelogginglog4jlog4j-to-slf4j2.10.0log4j-to-slf4j-2.10.0.jar;C:Userslitan.m2
epositoryorgapachelogginglog4jlog4j-api2.10.0log4j-api-2.10.0.jar;C:Userslitan.m2
epositoryorgslf4jjul-to-slf4j1.7.25jul-to-slf4j-1.7.25.jar;C:Userslitan.m2
epositoryjavaxannotationjavax.annotation-api1.3.2javax.annotation-api-1.3.2.jar;C:Userslitan.m2
epositoryorgyamlsnakeyaml1.19snakeyaml-1.19.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-json2.0.5.RELEASEspring-boot-starter-json-2.0.5.RELEASE.jar;C:Userslitan.m2
epositorycomfasterxmljacksoncorejackson-databind2.9.6jackson-databind-2.9.6.jar;C:Userslitan.m2
epositorycomfasterxmljacksoncorejackson-annotations2.9.0jackson-annotations-2.9.0.jar;C:Userslitan.m2
epositorycomfasterxmljacksoncorejackson-core2.9.6jackson-core-2.9.6.jar;C:Userslitan.m2
epositorycomfasterxmljacksondatatypejackson-datatype-jdk82.9.6jackson-datatype-jdk8-2.9.6.jar;C:Userslitan.m2
epositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.9.6jackson-datatype-jsr310-2.9.6.jar;C:Userslitan.m2
epositorycomfasterxmljacksonmodulejackson-module-parameter-names2.9.6jackson-module-parameter-names-2.9.6.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-tomcat2.0.5.RELEASEspring-boot-starter-tomcat-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgapache	omcatembed	omcat-embed-core8.5.34	omcat-embed-core-8.5.34.jar;C:Userslitan.m2
epositoryorgapache	omcatembed	omcat-embed-el8.5.34	omcat-embed-el-8.5.34.jar;C:Userslitan.m2
epositoryorgapache	omcatembed	omcat-embed-websocket8.5.34	omcat-embed-websocket-8.5.34.jar;C:Userslitan.m2
epositoryorghibernatevalidatorhibernate-validator6.0.12.Finalhibernate-validator-6.0.12.Final.jar;C:Userslitan.m2
epositoryjavaxvalidationvalidation-api2.0.1.Finalvalidation-api-2.0.1.Final.jar;C:Userslitan.m2
epositoryorgjbossloggingjboss-logging3.3.2.Finaljboss-logging-3.3.2.Final.jar;C:Userslitan.m2
epositorycomfasterxmlclassmate1.3.4classmate-1.3.4.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-web5.0.9.RELEASEspring-web-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-beans5.0.9.RELEASEspring-beans-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-webmvc5.0.9.RELEASEspring-webmvc-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-aop5.0.9.RELEASEspring-aop-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-context5.0.9.RELEASEspring-context-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-expression5.0.9.RELEASEspring-expression-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgmybatisspringootmybatis-spring-boot-starter1.3.2mybatis-spring-boot-starter-1.3.2.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-jdbc2.0.5.RELEASEspring-boot-starter-jdbc-2.0.5.RELEASE.jar;C:Userslitan.m2
epositorycomzaxxerHikariCP2.7.9HikariCP-2.7.9.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-jdbc5.0.9.RELEASEspring-jdbc-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-tx5.0.9.RELEASEspring-tx-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgmybatisspringootmybatis-spring-boot-autoconfigure1.3.2mybatis-spring-boot-autoconfigure-1.3.2.jar;C:Userslitan.m2
epositoryorgmybatismybatis3.4.6mybatis-3.4.6.jar;C:Userslitan.m2
epositoryorgmybatismybatis-spring1.3.2mybatis-spring-1.3.2.jar;C:Userslitan.m2
epositorymysqlmysql-connector-java5.1.47mysql-connector-java-5.1.47.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-starter-test2.0.5.RELEASEspring-boot-starter-test-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-test2.0.5.RELEASEspring-boot-test-2.0.5.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkootspring-boot-test-autoconfigure2.0.5.RELEASEspring-boot-test-autoconfigure-2.0.5.RELEASE.jar;C:Userslitan.m2
epositorycomjaywayjsonpathjson-path2.4.0json-path-2.4.0.jar;C:Userslitan.m2
epository
etminidevjson-smart2.3json-smart-2.3.jar;C:Userslitan.m2
epository
etminidevaccessors-smart1.2accessors-smart-1.2.jar;C:Userslitan.m2
epositoryorgow2asmasm5.0.4asm-5.0.4.jar;C:Userslitan.m2
epositoryorgslf4jslf4j-api1.7.25slf4j-api-1.7.25.jar;C:Userslitan.m2
epositoryjunitjunit4.12junit-4.12.jar;C:Userslitan.m2
epositoryorgassertjassertj-core3.9.1assertj-core-3.9.1.jar;C:Userslitan.m2
epositoryorgmockitomockito-core2.15.0mockito-core-2.15.0.jar;C:Userslitan.m2
epository
etytebuddyyte-buddy1.7.11yte-buddy-1.7.11.jar;C:Userslitan.m2
epository
etytebuddyyte-buddy-agent1.7.11yte-buddy-agent-1.7.11.jar;C:Userslitan.m2
epositoryorgobjenesisobjenesis2.6objenesis-2.6.jar;C:Userslitan.m2
epositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;C:Userslitan.m2
epositoryorghamcresthamcrest-library1.3hamcrest-library-1.3.jar;C:Userslitan.m2
epositoryorgskyscreamerjsonassert1.5.0jsonassert-1.5.0.jar;C:Userslitan.m2
epositorycomvaadinexternalgoogleandroid-json.0.20131108.vaadin1android-json-0.0.20131108.vaadin1.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-core5.0.9.RELEASEspring-core-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-jcl5.0.9.RELEASEspring-jcl-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgspringframeworkspring-test5.0.9.RELEASEspring-test-5.0.9.RELEASE.jar;C:Userslitan.m2
epositoryorgxmlunitxmlunit-core2.5.1xmlunit-core-2.5.1.jar;D:javaDevlepTooleclipse4.8eclipseconfigurationorg.eclipse.osgi416.cp;D:javaDevlepTooleclipse4.8eclipseconfigurationorg.eclipse.osgi415.cp, user.name=litan, java.vm.specification.version=1.8, sun.java.command=org.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 52767 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -test com.zxy.demo.ElkApplicationTests:testLog, java.home=D:javajava1.8jre1.8, sun.arch.data.model=64, user.language=zh, java.specification.vendor=Oracle Corporation, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, java.version=1.8.0_161, java.ext.dirs=D:javajava1.8jre1.8libext;C:WINDOWSSunJavalibext, sun.boot.class.path=D:javajava1.8jre1.8lib
esources.jar;D:javajava1.8jre1.8lib
t.jar;D:javajava1.8jre1.8libsunrsasign.jar;D:javajava1.8jre1.8libjsse.jar;D:javajava1.8jre1.8libjce.jar;D:javajava1.8jre1.8libcharsets.jar;D:javajava1.8jre1.8libjfr.jar;D:javajava1.8jre1.8classes, java.vendor=Oracle Corporation, file.separator=, java.vendor.url.bug=http://bugreport.sun.com/bugreport/, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, sun.cpu.isalist=amd64}}, [email protected] {name=‘systemEnvironment‘, properties={configsetroot=C:WINDOWSConfigSetRoot, USERDOMAIN_ROAMINGPROFILE=LITAN, PROCESSOR_LEVEL=6, SESSIONNAME=Console, ALLUSERSPROFILE=C:ProgramData, PROCESSOR_ARCHITECTURE=AMD64, PSModulePath=C:Program FilesWindowsPowerShellModules;C:WINDOWSsystem32WindowsPowerShellv1.0Modules;D:我的软件办公软件svnServerPowerShellModules, SystemDrive=C:, MAVEN_HOME=D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9, USERNAME=litan, ProgramFiles(x86)=C:Program Files (x86), VISUALSVN_SERVER=D:我的软件办公软件svnServer, FPS_BROWSER_USER_PROFILE_STRING=Default, PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC, DriverData=C:WindowsSystem32DriversDriverData, ProgramData=C:ProgramData, ProgramW6432=C:Program Files, HOMEPATH=Userslitan, PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 61 Stepping 4, GenuineIntel, ProgramFiles=C:Program Files, PUBLIC=C:UsersPublic, windir=C:WINDOWS, =::=::, ZOOKEEPER_HOME=D:我的软件专业软件zookeeperzookeeper-3.4.9, LOCALAPPDATA=C:UserslitanAppDataLocal, USERDOMAIN=LITAN, FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer, LOGONSERVER=\\LITAN, JAVA_HOME=D:javajava1.8jdk1.8, ERLANG_HOME=D:	opbandsoftRabbitMQerl7.1, OneDrive=C:UserslitanOneDrive, =C:=C:, APPDATA=C:UserslitanAppDataRoaming, CommonProgramFiles=C:Program FilesCommon Files, Path=C:ProgramDataOracleJavajavapath;D:javaoracleproduct11.2.0dbhome_1in;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:Program Files (x86)Common Fileslenovoeasyplussdkin;C:Program Files (x86)ATI TechnologiesATI.ACECore-Static;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5;C:Program Files (x86)MySQLMySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5Doctrine extensions for PHP;D:javajava1.8jdk1.8in;JAVA_HOME%jrein;D:java_reviewapache-tomcat-7.0.67in;D:我的软件;办公软;svnServerin;%ma;en_home%in;D:我的软件数据库putty;C:Pro;ram FilesIntelWiFiin;C:Program FilesCommon FilesIntelWirelessCommon;";D:我的软件专业软件zookeeperzookeeper-3.4.9/bin; D:我的软件专业软件zookeeperzookeeper-3.4.9/conf";D:javajava1.8jdk1.8in;C:Program FilesTortoiseGitin;C:Program FilesGitcmd;C:WINDOWSSystem32OpenSSH;D:java软件安装资源汇总maven建项目apache-maven-3.3.9-binapache-maven-3.3.9in;D:protobufcin;C:UserslitanAppDataLocalMicrosoftWindowsApps;D:java软件安装资源汇总2017-6-25apache-maven-3.3.9-binapache-maven-3.3.9in;, OS=Windows_NT, COMPUTERNAME=LITAN, CATALINA_HOME=D:java_reviewapache-tomcat-7.0.67, PROCESSOR_REVISION=3d04, CLASSPATH=.;D:javajava1.8jdk1.8lib;D:javajava1.8jdk1.8lib	ools.jar, CommonProgramW6432=C:Program FilesCommon Files, ComSpec=C:WINDOWSsystem32cmd.exe, SystemRoot=C:WINDOWS, TEMP=C:UserslitanAppDataLocalTemp, HOMEDRIVE=C:, USERPROFILE=C:Userslitan, TMP=C:UserslitanAppDataLocalTemp, easyplussdk="C:Program Files (x86)Common Fileslenovoeasyplussdkin", CommonProgramFiles(x86)=C:Program Files (x86)Common Files, NUMBER_OF_PROCESSORS=4}}]
43 13:13:24.868 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}
44 13:13:24.868 [main] DEBUG org.springframework.core.env.StandardEnvironment - Adding PropertySource ‘Inlined Test Properties‘ with highest search precedence
45 13:13:25,330 |-WARN in Logger[org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator] - No appenders present in context [default] for logger [org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator].
46 13:13:25,359 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Will scan for changes in [file:/D:/worksheet/elk/target/classes/logback-spring.xml] 
47 13:13:25,359 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeTask scanning period to 1 minutes
48 13:13:25,364 |-INFO in ch.qos.logback.classic.joran.action.ContextNameAction - Setting logger context name as [elk]
49 13:13:25,365 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
50 13:13:25,365 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
51 13:13:25,396 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
52 13:13:25,399 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE]
53 13:13:25,412 |-INFO in [email protected] - No compression will be used
54 13:13:25,414 |-INFO in [email protected] - Will use the pattern d://%d{yyyy-MM-dd}/error-log.log for the active file
55 13:13:25,420 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is ‘yyyy-MM-dd‘ from file name pattern ‘d://%d{yyyy-MM-dd}/error-log.log‘.
56 13:13:25,420 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
57 13:13:25,424 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Mon Oct 01 12:39:50 CST 2018
58 13:13:25,429 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: d://elk.log
59 13:13:25,429 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [d://elk.log]
60 13:13:25,431 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.apache.ibatis] to TRACE
61 13:13:25,432 |-INFO in [email protected] - Propagating TRACE level on Logger[com.apache.ibatis] onto the JUL framework
62 13:13:25,432 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [java.sql.Connection] to DEBUG
63 13:13:25,432 |-INFO in [email protected] - Propagating DEBUG level on Logger[java.sql.Connection] onto the JUL framework
64 13:13:25,433 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [java.sql.Statement] to DEBUG
65 13:13:25,433 |-INFO in [email protected] - Propagating DEBUG level on Logger[java.sql.Statement] onto the JUL framework
66 13:13:25,433 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [java.sql.PreparedStatement] to DEBUG
67 13:13:25,433 |-INFO in [email protected] - Propagating DEBUG level on Logger[java.sql.PreparedStatement] onto the JUL framework
68 13:13:25,433 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
69 13:13:25,433 |-INFO in [email protected] - Propagating INFO level on Logger[ROOT] onto the JUL framework
70 13:13:25,433 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
71 13:13:25,433 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to Logger[ROOT]
72 13:13:25,433 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
73 13:13:25,434 |-INFO in org.s[email protected]642a7222 - Registering current configuration as safe fallback point
74 
75   .   ____          _            __ _ _
76  /\\ / ___‘_ __ _ _(_)_ __  __ _    77 ( ( )\\___ | ‘_ | ‘_| | ‘_ / _` |    78  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
79   ‘  |____| .__|_| |_|_| |_\\__, | / / / /
80  =========|_|==============|___/=/_/_/_/
81  :: Spring Boot ::        (v2.0.5.RELEASE)
82 
83 2018-10-01 13:13:25.640 {main} INFO  com.zxy.demo.ElkApplicationTests =======> Starting ElkApplicationTests on litan with PID 14856 (started by litan in D:worksheetelk)
84 2018-10-01 13:13:25.642 {main} INFO  com.zxy.demo.ElkApplicationTests =======> No active profile set, falling back to default profiles: default
85 2018-10-01 13:13:25.691 {main} INFO  o.s.w.context.support.GenericWebApplicationContext =======> Refreshing org.s[email protected]78fa769e: startup date [Mon Oct 01 13:13:25 CST 2018]; root of context hierarchy
86 2018-10-01 13:13:26.666 {main} WARN  org.mybatis.spring.mapper.ClassPathMapperScanner =======> No MyBatis mapper was found in ‘[com.zxy.demo]‘ package. Please check your configuration.
87 2018-10-01 13:13:27.814 {main} INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping =======> Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
88 2018-10-01 13:13:28.153 {main} INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter =======> Looking for @ControllerAdvice: org.s[email protected]78fa769e: startup date [Mon Oct 01 13:13:25 CST 2018]; root of context hierarchy
89 2018-10-01 13:13:28.262 {main} INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping =======> Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
90 2018-10-01 13:13:28.265 {main} INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping =======> Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
91 2018-10-01 13:13:28.312 {main} INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping =======> Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
92 2018-10-01 13:13:28.313 {main} INFO  o.s.web.servlet.handler.SimpleUrlHandlerMapping =======> Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
93 2018-10-01 13:13:28.911 {main} INFO  com.zxy.demo.ElkApplicationTests =======> Started ElkApplicationTests in 4.026 seconds (JVM running for 5.307)
94 2018-10-01 13:13:29.392 {main} INFO  com.zxy.demo.ElkApplicationTests =======> message:this is first logger!
95 2018-10-01 13:13:29.401 {Thread-2} INFO  o.s.w.context.support.GenericWebApplicationContext =======> Closing org.s[email protected]78fa769e: startup date [Mon Oct 01 13:13:25 CST 2018]; root of context hierarchy
View Code

d:/elk.log也有日志打印了,OK!

接下来,我们来整合elk,elk在上一篇章中已经搭建完成,我们这里需要将日志输出到logstash存储到elasticsearch中,通过kibana进行显示即可。

在工程中添加logstash-logback的依赖

1 <!-- https://mvnrepository.com/artifact/net.logstash.logback/logstash-logback-encoder -->
2 <dependency>
3     <groupId>net.logstash.logback</groupId>
4     <artifactId>logstash-logback-encoder</artifactId>
5     <version>4.11</version>
6 </dependency>

写一个logstash的配置文件,启动logstash时候采用该配置文件进行启动。

配置文件如下:

 1 input {
 2     tcp {  
 3     ##host:port就是上面appender中的 destination,这里其实把logstash作为服务,开启9601端口接收logback发出的消息  
 4         host => "192.168.10.194"  
 5         port => 9601  
 6     #模式选择为server  
 7         mode => "server"  
 8         tags => ["tags"]  
 9 
10     ##格式json  
11         codec => json_lines         
12     }  
13 
14 } 
15 
16 output {
17         elasticsearch {
18         #ES地址
19                 hosts => "192.168.10.194:9200"
20         #指定索引名字,不适用默认的,用来区分各个项目
21                 index => "%{[appname]}-%{+YYYY.MM.dd}"
22         }
23         stdout { codec => rubydebug}
24 }

在用户端启动elasticsearch,root端分别启动kibana和logstash,

在test单元测试中添加一句日志以示区别:

 1 package com.zxy.demo;
 2 
 3 import org.junit.Test;
 4 import org.junit.runner.RunWith;
 5 import org.slf4j.Logger;
 6 import org.slf4j.LoggerFactory;
 7 import org.springframework.boot.test.context.SpringBootTest;
 8 import org.springframework.test.context.junit4.SpringRunner;
 9 
10 @RunWith(SpringRunner.class)
11 @SpringBootTest
12 public class ElkApplicationTests {
13     private Logger logger = LoggerFactory.getLogger(this.getClass());
14 
15     @Test
16     public void contextLoads() {
17     }
18     @Test
19     public void testLog() {
20         logger.info("message:this is first logger!");
21         logger.info("msg:[********upload to logstash and elasticsearch,kibana view!!!********]");
22     }
23 }

然后运行springboot项目,打印日志在centos的控制台可见

技术分享图片

kibana上也能看到日志已经过来了

技术分享图片

总结,这里logback和elk的整合主要有三步:

一、添加logback-logstash的整合依赖包

二、编写logstash的配置文件,这个笔者认为比较灵活,如果对其语法不甚了解会比较难办

三、就是配置logback.xml了把输入的目标写好就OK了

以上是关于springboot整合logback集成elk实现日志的汇总分析统计和检索功能的主要内容,如果未能解决你的问题,请参考以下文章

elk平台集成log4jlog4j2logback日志

集成log4jlog4j2logback与elk

Java中多环境Logback配置与ELK日志发送

docker安装ELK 收集springboot日志(方法1)

springboot向elk写日志

SpringBoot 整合 elk