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 ch.qos.logback.core.joran.spi.Interpreter@19:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
 10 11:57:36,945 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@20:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
 11 11:57:36,946 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
 12 11:57:36,946 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
 13 11:57:36,947 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
 14 11:57:36,947 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@31: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 ch.qos.logback.classic.jul.LevelChangePropagator@5f058f00 - 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 ch.qos.logback.classic.jul.LevelChangePropagator@5f058f00 - 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 ch.qos.logback.classic.jul.LevelChangePropagator@5f058f00 - 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 ch.qos.logback.classic.jul.LevelChangePropagator@5f058f00 - 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 ch.qos.logback.classic.jul.LevelChangePropagator@5f058f00 - 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.springframework.boot.logging.logback.SpringBootJoranConfigurator@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 ch.qos.logback.core.joran.spi.Interpreter@19:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
 33 ERROR in ch.qos.logback.core.joran.spi.Interpreter@20:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
 34 ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
 35 ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
 36 ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
 37 ERROR in ch.qos.logback.core.joran.spi.Interpreter@31: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 ch.qos.logback.core.joran.spi.Interpreter@19:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
 60 ERROR in ch.qos.logback.core.joran.spi.Interpreter@20:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
 61 ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
 62 ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
 63 ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
 64 ERROR in ch.qos.logback.core.joran.spi.Interpreter@31: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 ch.qos.logback.core.joran.spi.Interpreter@19:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
 82 ERROR in ch.qos.logback.core.joran.spi.Interpreter@20:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
 83 ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
 84 ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
 85 ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
 86 ERROR in ch.qos.logback.core.joran.spi.Interpreter@31: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 ch.qos.logback.core.joran.spi.Interpreter@19:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
 95 ERROR in ch.qos.logback.core.joran.spi.Interpreter@20:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
 96 ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
 97 ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
 98 ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
 99 ERROR in ch.qos.logback.core.joran.spi.Interpreter@31: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 ch.qos.logback.core.joran.spi.Interpreter@19:19 - no applicable action for [Encoding], current ElementPath  is [[configuration][appender][Encoding]]
117 ERROR in ch.qos.logback.core.joran.spi.Interpreter@20:68 - no applicable action for [rollingPolicy], current ElementPath  is [[configuration][appender][rollingPolicy]]
118 ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:21 - no applicable action for [FileNamePattern], current ElementPath  is [[configuration][appender][rollingPolicy][FileNamePattern]]
119 ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:16 - no applicable action for [MaxHistory], current ElementPath  is [[configuration][appender][rollingPolicy][MaxHistory]]
120 ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:83 - no applicable action for [triggeringPolicy], current ElementPath  is [[configuration][appender][triggeringPolicy]]
121 ERROR in ch.qos.logback.core.joran.spi.Interpreter@31: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代码更改后:

<?xml version="1.0" encoding="UTF-8"?>
<!-- 设置配置文件如果改动自动加载,监测是否修改时间间隔为60s,不打印logback内部日志信息 -->
<configuration scan="true" scanPeriod="60 seconds" debug="true">
    <!--设置上下文名称  -->
    <property name="appName" value="elk"/>
    <contextName>${appName}</contextName>
    <!-- <timestamp key="" datePattern=""/> -->
    <!-- 存放日志地址 -->
    <property name="log_home" value="d:/"/>
    <!-- 控制台输出 -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} {%thread} %-5level %logger{50} =======> %msg%n</pattern>
        </encoder>
    </appender>
    <!-- 滚动记录日志 -->
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">  <!-- 类要引用正确ch.qos.logback.core.FileAppender -->
        <file>${log_home}/elk.log</file>  <!-- 引用ch.qos.logback.core.FileAppender需要的属性,这里不需要-->
        <!--     <append>true</append> -->
        <!--   <Encoding>UTF-8</Encoding>   1.17版本后不能用,去掉 -->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 不是ch.qos.logback.core.rolling.RollingPolicy -->
            <!-- 日志文件输出的文件名 -->
            <fileNamePattern>${log_home}/%d{yyyy-MM-dd}/error-log.log</fileNamePattern>
            <!-- 日志保留30天 -->
            <maxHistory>30</maxHistory>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <!--  格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符  -->
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} {%thread} %-5level %logger{50} =======> %msg%n</pattern>
        </encoder>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10MB</MaxFileSize>
        </triggeringPolicy>
    </appender>

    <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>192.168.xx.xxx:xxxx</destination>
        <!-- encoder必须配置,有多种可选 -->
        <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
            <providers>
                <timestamp>
                    <timeZone>UTC</timeZone>
                </timestamp>
                <pattern>
                    <pattern>
                        {
                        "severity": "%level",
                        "service": "${springAppName:-}",
                        "trace": "%X{X-B3-TraceId:-}",
                        "span": "%X{X-B3-SpanId:-}",
                        "exportable": "%X{X-Span-Export:-}",
                        "pid": "${PID:-}",
                        "thread": "%thread",
                        "class": "%logger{40}",
                        "rest": "%message"
                        }
                    </pattern>
                </pattern>
            </providers>
            <customFields>{"project":"elasticsearch-test"}</customFields>
        </encoder>
    </appender>
    <!--myibatis log configure-->
    <logger name="com.apache.ibatis" level="TRACE"/>
    <logger name="java.sql.Connection" level="DEBUG"/>
    <logger name="java.sql.Statement" level="DEBUG"/>
    <logger name="java.sql.PreparedStatement" level="DEBUG"/>
    <!-- 日志输出级别 -->
    <root level="INFO">
        <appender-ref ref="stash" />
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILE" />
    </root>
    <!--
     日志异步到数据库
     <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
         日志异步到数据库
         <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
            连接池
            <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
               <driverClass>com.mysql.jdbc.Driver</driverClass>
               <url>jdbc:mysql://127.0.0.1:3306/databaseName</url>
               <user>root</user>
               <password>root</password>
             </dataSource>
         </connectionSource>
   </appender> -->
</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 [MapPropertySource@1630521067 {name='systemProperties', properties={java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=D:\java\java1.8\jre1.8\bin, 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:\worksheet\elk, java.runtime.version=1.8.0_161-b12, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=D:\java\java1.8\jre1.8\lib\endorsed, os.arch=amd64, java.io.tmpdir=C:\Users\litan\AppData\Local\Temp\, line.separator=
14 , java.vm.specification.vendor=Oracle Corporation, user.variant=, os.name=Windows 10, sun.jnu.encoding=GBK, java.library.path=D:\java\java1.8\jre1.8\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\ProgramData\Oracle\Java\javapath;D:\java\oracle\product\11.2.0\dbhome_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5\Doctrine extensions for PHP\;D:\java\java1.8\jdk1.8\bin;JAVA_HOME%\jre\bin;D:\java\Z_review\apache-tomcat-7.0.67\bin;D:\我的软件;办公软;\svnServer\bin;%ma;en_home%\bin;D:\我的软件\数据库\putty\;C:\Pro;ram Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;";D:\我的软件\专业软件\zookeeper\zookeeper-3.4.9/bin; D:\我的软件\专业软件\zookeeper\zookeeper-3.4.9/conf";D:\java\java1.8\jdk1.8\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\Git\cmd;C:\WINDOWS\System32\OpenSSH\;D:\java软件安装资源汇总\maven建项目\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;D:\protobufc\bin;C:\Users\litan\AppData\Local\Microsoft\WindowsApps;D:\java软件安装资源汇总\2017-6-25\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;;., 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:\Users\litan, user.timezone=Asia/Shanghai, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=UTF-8, java.specification.version=1.8, java.class.path=D:\worksheet\elk\target\test-classes;D:\worksheet\elk\target\classes;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.0.5.RELEASE\spring-boot-starter-web-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter\2.0.5.RELEASE\spring-boot-starter-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot\2.0.5.RELEASE\spring-boot-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.0.5.RELEASE\spring-boot-autoconfigure-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.0.5.RELEASE\spring-boot-starter-logging-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\litan\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\litan\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.10.0\log4j-to-slf4j-2.10.0.jar;C:\Users\litan\.m2\repository\org\apache\logging\log4j\log4j-api\2.10.0\log4j-api-2.10.0.jar;C:\Users\litan\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\litan\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\litan\.m2\repository\org\yaml\snakeyaml\1.19\snakeyaml-1.19.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.0.5.RELEASE\spring-boot-starter-json-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.6\jackson-databind-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.6\jackson-core-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.6\jackson-datatype-jdk8-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.6\jackson-datatype-jsr310-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.6\jackson-module-parameter-names-2.9.6.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.0.5.RELEASE\spring-boot-starter-tomcat-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\8.5.34\tomcat-embed-core-8.5.34.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\8.5.34\tomcat-embed-el-8.5.34.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\8.5.34\tomcat-embed-websocket-8.5.34.jar;C:\Users\litan\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.12.Final\hibernate-validator-6.0.12.Final.jar;C:\Users\litan\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\litan\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\litan\.m2\repository\com\fasterxml\classmate\1.3.4\classmate-1.3.4.jar;C:\Users\litan\.m2\repository\org\springframework\spring-web\5.0.9.RELEASE\spring-web-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-beans\5.0.9.RELEASE\spring-beans-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-webmvc\5.0.9.RELEASE\spring-webmvc-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-aop\5.0.9.RELEASE\spring-aop-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-context\5.0.9.RELEASE\spring-context-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-expression\5.0.9.RELEASE\spring-expression-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-starter\1.3.2\mybatis-spring-boot-starter-1.3.2.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.0.5.RELEASE\spring-boot-starter-jdbc-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\com\zaxxer\HikariCP\2.7.9\HikariCP-2.7.9.jar;C:\Users\litan\.m2\repository\org\springframework\spring-jdbc\5.0.9.RELEASE\spring-jdbc-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-tx\5.0.9.RELEASE\spring-tx-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\1.3.2\mybatis-spring-boot-autoconfigure-1.3.2.jar;C:\Users\litan\.m2\repository\org\mybatis\mybatis\3.4.6\mybatis-3.4.6.jar;C:\Users\litan\.m2\repository\org\mybatis\mybatis-spring\1.3.2\mybatis-spring-1.3.2.jar;C:\Users\litan\.m2\repository\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-test\2.0.5.RELEASE\spring-boot-starter-test-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-test\2.0.5.RELEASE\spring-boot-test-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-test-autoconfigure\2.0.5.RELEASE\spring-boot-test-autoconfigure-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;C:\Users\litan\.m2\repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;C:\Users\litan\.m2\repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;C:\Users\litan\.m2\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;C:\Users\litan\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\litan\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\litan\.m2\repository\org\assertj\assertj-core\3.9.1\assertj-core-3.9.1.jar;C:\Users\litan\.m2\repository\org\mockito\mockito-core\2.15.0\mockito-core-2.15.0.jar;C:\Users\litan\.m2\repository\net\bytebuddy\byte-buddy\1.7.11\byte-buddy-1.7.11.jar;C:\Users\litan\.m2\repository\net\bytebuddy\byte-buddy-agent\1.7.11\byte-buddy-agent-1.7.11.jar;C:\Users\litan\.m2\repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;C:\Users\litan\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\litan\.m2\repository\org\hamcrest\hamcrest-library\1.3\hamcrest-library-1.3.jar;C:\Users\litan\.m2\repository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;C:\Users\litan\.m2\repository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;C:\Users\litan\.m2\repository\org\springframework\spring-core\5.0.9.RELEASE\spring-core-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-jcl\5.0.9.RELEASE\spring-jcl-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-test\5.0.9.RELEASE\spring-test-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\xmlunit\xmlunit-core\2.5.1\xmlunit-core-2.5.1.jar;D:\javaDevlepTool\eclipse4.8\eclipse\configuration\org.eclipse.osgi\416\0\.cp;D:\javaDevlepTool\eclipse4.8\eclipse\configuration\org.eclipse.osgi\415\0\.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:\java\java1.8\jre1.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:\java\java1.8\jre1.8\lib\ext;C:\WINDOWS\Sun\Java\lib\ext, sun.boot.class.path=D:\java\java1.8\jre1.8\lib\resources.jar;D:\java\java1.8\jre1.8\lib\rt.jar;D:\java\java1.8\jre1.8\lib\sunrsasign.jar;D:\java\java1.8\jre1.8\lib\jsse.jar;D:\java\java1.8\jre1.8\lib\jce.jar;D:\java\java1.8\jre1.8\lib\charsets.jar;D:\java\java1.8\jre1.8\lib\jfr.jar;D:\java\java1.8\jre1.8\classes, 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}}, SystemEnvironmentPropertySource@274773041 {name='systemEnvironment', properties={configsetroot=C:\WINDOWS\ConfigSetRoot, USERDOMAIN_ROAMINGPROFILE=LITAN, PROCESSOR_LEVEL=6, SESSIONNAME=Console, ALLUSERSPROFILE=C:\ProgramData, PROCESSOR_ARCHITECTURE=AMD64, PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules;D:\我的软件\办公软件\svnServer\PowerShellModules, SystemDrive=C:, MAVEN_HOME=D:\java软件安装资源汇总\maven建项目\apache-maven-3.3.9-bin\apache-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:\Windows\System32\Drivers\DriverData, ProgramData=C:\ProgramData, ProgramW6432=C:\Program Files, HOMEPATH=\Users\litan, PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 61 Stepping 4, GenuineIntel, ProgramFiles=C:\Program Files, PUBLIC=C:\Users\Public, windir=C:\WINDOWS, =::=::\, ZOOKEEPER_HOME=D:\我的软件\专业软件\zookeeper\zookeeper-3.4.9, LOCALAPPDATA=C:\Users\litan\AppData\Local, USERDOMAIN=LITAN, FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer, LOGONSERVER=\\LITAN, JAVA_HOME=D:\java\java1.8\jdk1.8, ERLANG_HOME=D:\topband\soft\RabbitMQ\erl7.1, OneDrive=C:\Users\litan\OneDrive, =C:=C:\, APPDATA=C:\Users\litan\AppData\Roaming, CommonProgramFiles=C:\Program Files\Common Files, Path=C:\ProgramData\Oracle\Java\javapath;D:\java\oracle\product\11.2.0\dbhome_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5\Doctrine extensions for PHP\;D:\java\java1.8\jdk1.8\bin;JAVA_HOME%\jre\bin;D:\java\Z_review\apache-tomcat-7.0.67\bin;D:\我的软件;办公软;\svnServer\bin;%ma;en_home%\bin;D:\我的软件\数据库\putty\;C:\Pro;ram Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;";D:\我的软件\专业软件\zookeeper\zookeeper-3.4.9/bin; D:\我的软件\专业软件\zookeeper\zookeeper-3.4.9/conf";D:\java\java1.8\jdk1.8\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\Git\cmd;C:\WINDOWS\System32\OpenSSH\;D:\java软件安装资源汇总\maven建项目\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;D:\protobufc\bin;C:\Users\litan\AppData\Local\Microsoft\WindowsApps;D:\java软件安装资源汇总\2017-6-25\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;, OS=Windows_NT, COMPUTERNAME=LITAN, CATALINA_HOME=D:\java\Z_review\apache-tomcat-7.0.67, PROCESSOR_REVISION=3d04, CLASSPATH=.;D:\java\java1.8\jdk1.8\lib;D:\java\java1.8\jdk1.8\lib\tools.jar, CommonProgramW6432=C:\Program Files\Common Files, ComSpec=C:\WINDOWS\system32\cmd.exe, SystemRoot=C:\WINDOWS, TEMP=C:\Users\litan\AppData\Local\Temp, HOMEDRIVE=C:, USERPROFILE=C:\Users\litan, TMP=C:\Users\litan\AppData\Local\Temp, easyplussdk="C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin", 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:\worksheet\elk\target\test-classes\com\zxy\demo]
17 13:13:24.514 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Searching directory [D:\worksheet\elk\target\test-classes\com\zxy\demo] 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:\worksheet\elk\target\classes\com\zxy\demo]
19 13:13:24.518 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Searching directory [D:\worksheet\elk\target\classes\com\zxy\demo] 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:\worksheet\elk\target\test-classes\com\zxy\demo\ElkApplicationTests.class], file [D:\worksheet\elk\target\classes\com\zxy\demo\ElkApplication.class]]
21 13:13:24.585 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [D:\worksheet\elk\target\classes\com\zxy\demo\ElkApplication.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: [org.springframework.test.context.web.ServletTestExecutionListener@79924b, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@7b9a4292, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@4a94ee4, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@4cc451f2, org.springframework.test.context.support.DirtiesContextTestExecutionListener@6379eb, org.springframework.test.context.transaction.TransactionalTestExecutionListener@294425a7, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@67d48005, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@9f116cc, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@12468a38, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@1aa7ecca, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@59309333, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@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 [DefaultTestContext@223191a6 testClass = ElkApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@49139829 testClass = ElkApplicationTests, locations = '{}', classes = '{class com.zxy.demo.ElkApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@15d0c81b, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@17579e0f, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@7a765367, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@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 [MapPropertySource@331994761 {name='systemProperties', properties={java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=D:\java\java1.8\jre1.8\bin, 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:\worksheet\elk, java.runtime.version=1.8.0_161-b12, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=D:\java\java1.8\jre1.8\lib\endorsed, os.arch=amd64, java.io.tmpdir=C:\Users\litan\AppData\Local\Temp\, line.separator=
42 , java.vm.specification.vendor=Oracle Corporation, user.variant=, os.name=Windows 10, sun.jnu.encoding=GBK, java.library.path=D:\java\java1.8\jre1.8\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\ProgramData\Oracle\Java\javapath;D:\java\oracle\product\11.2.0\dbhome_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5\Doctrine extensions for PHP\;D:\java\java1.8\jdk1.8\bin;JAVA_HOME%\jre\bin;D:\java\Z_review\apache-tomcat-7.0.67\bin;D:\我的软件;办公软;\svnServer\bin;%ma;en_home%\bin;D:\我的软件\数据库\putty\;C:\Pro;ram Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;";D:\我的软件\专业软件\zookeeper\zookeeper-3.4.9/bin; D:\我的软件\专业软件\zookeeper\zookeeper-3.4.9/conf";D:\java\java1.8\jdk1.8\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\Git\cmd;C:\WINDOWS\System32\OpenSSH\;D:\java软件安装资源汇总\maven建项目\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;D:\protobufc\bin;C:\Users\litan\AppData\Local\Microsoft\WindowsApps;D:\java软件安装资源汇总\2017-6-25\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;;., 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:\Users\litan, user.timezone=Asia/Shanghai, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=UTF-8, java.specification.version=1.8, java.class.path=D:\worksheet\elk\target\test-classes;D:\worksheet\elk\target\classes;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.0.5.RELEASE\spring-boot-starter-web-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter\2.0.5.RELEASE\spring-boot-starter-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot\2.0.5.RELEASE\spring-boot-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.0.5.RELEASE\spring-boot-autoconfigure-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.0.5.RELEASE\spring-boot-starter-logging-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\litan\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\litan\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.10.0\log4j-to-slf4j-2.10.0.jar;C:\Users\litan\.m2\repository\org\apache\logging\log4j\log4j-api\2.10.0\log4j-api-2.10.0.jar;C:\Users\litan\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\litan\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\litan\.m2\repository\org\yaml\snakeyaml\1.19\snakeyaml-1.19.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.0.5.RELEASE\spring-boot-starter-json-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.6\jackson-databind-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.6\jackson-core-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.6\jackson-datatype-jdk8-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.6\jackson-datatype-jsr310-2.9.6.jar;C:\Users\litan\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.6\jackson-module-parameter-names-2.9.6.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.0.5.RELEASE\spring-boot-starter-tomcat-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\8.5.34\tomcat-embed-core-8.5.34.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\8.5.34\tomcat-embed-el-8.5.34.jar;C:\Users\litan\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\8.5.34\tomcat-embed-websocket-8.5.34.jar;C:\Users\litan\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.12.Final\hibernate-validator-6.0.12.Final.jar;C:\Users\litan\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\litan\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\litan\.m2\repository\com\fasterxml\classmate\1.3.4\classmate-1.3.4.jar;C:\Users\litan\.m2\repository\org\springframework\spring-web\5.0.9.RELEASE\spring-web-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-beans\5.0.9.RELEASE\spring-beans-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-webmvc\5.0.9.RELEASE\spring-webmvc-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-aop\5.0.9.RELEASE\spring-aop-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-context\5.0.9.RELEASE\spring-context-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-expression\5.0.9.RELEASE\spring-expression-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-starter\1.3.2\mybatis-spring-boot-starter-1.3.2.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.0.5.RELEASE\spring-boot-starter-jdbc-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\com\zaxxer\HikariCP\2.7.9\HikariCP-2.7.9.jar;C:\Users\litan\.m2\repository\org\springframework\spring-jdbc\5.0.9.RELEASE\spring-jdbc-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-tx\5.0.9.RELEASE\spring-tx-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\1.3.2\mybatis-spring-boot-autoconfigure-1.3.2.jar;C:\Users\litan\.m2\repository\org\mybatis\mybatis\3.4.6\mybatis-3.4.6.jar;C:\Users\litan\.m2\repository\org\mybatis\mybatis-spring\1.3.2\mybatis-spring-1.3.2.jar;C:\Users\litan\.m2\repository\mysql\mysql-connector-java\5.1.47\mysql-connector-java-5.1.47.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-starter-test\2.0.5.RELEASE\spring-boot-starter-test-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-test\2.0.5.RELEASE\spring-boot-test-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\boot\spring-boot-test-autoconfigure\2.0.5.RELEASE\spring-boot-test-autoconfigure-2.0.5.RELEASE.jar;C:\Users\litan\.m2\repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;C:\Users\litan\.m2\repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;C:\Users\litan\.m2\repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;C:\Users\litan\.m2\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;C:\Users\litan\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\litan\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\litan\.m2\repository\org\assertj\assertj-core\3.9.1\assertj-core-3.9.1.jar;C:\Users\litan\.m2\repository\org\mockito\mockito-core\2.15.0\mockito-core-2.15.0.jar;C:\Users\litan\.m2\repository\net\bytebuddy\byte-buddy\1.7.11\byte-buddy-1.7.11.jar;C:\Users\litan\.m2\repository\net\bytebuddy\byte-buddy-agent\1.7.11\byte-buddy-agent-1.7.11.jar;C:\Users\litan\.m2\repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;C:\Users\litan\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\litan\.m2\repository\org\hamcrest\hamcrest-library\1.3\hamcrest-library-1.3.jar;C:\Users\litan\.m2\repository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;C:\Users\litan\.m2\repository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;C:\Users\litan\.m2\repository\org\springframework\spring-core\5.0.9.RELEASE\spring-core-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-jcl\5.0.9.RELEASE\spring-jcl-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\springframework\spring-test\5.0.9.RELEASE\spring-test-5.0.9.RELEASE.jar;C:\Users\litan\.m2\repository\org\xmlunit\xmlunit-core\2.5.1\xmlunit-core-2.5.1.jar;D:\javaDevlepTool\eclipse4.8\eclipse\configuration\org.eclipse.osgi\416\0\.cp;D:\javaDevlepTool\eclipse4.8\eclipse\configuration\org.eclipse.osgi\415\0\.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:\java\java1.8\jre1.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:\java\java1.8\jre1.8\lib\ext;C:\WINDOWS\Sun\Java\lib\ext, sun.boot.class.path=D:\java\java1.8\jre1.8\lib\resources.jar;D:\java\java1.8\jre1.8\lib\rt.jar;D:\java\java1.8\jre1.8\lib\sunrsasign.jar;D:\java\java1.8\jre1.8\lib\jsse.jar;D:\java\java1.8\jre1.8\lib\jce.jar;D:\java\java1.8\jre1.8\lib\charsets.jar;D:\java\java1.8\jre1.8\lib\jfr.jar;D:\java\java1.8\jre1.8\classes, 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}}, SystemEnvironmentPropertySource@928294079 {name='systemEnvironment', properties={configsetroot=C:\WINDOWS\ConfigSetRoot, USERDOMAIN_ROAMINGPROFILE=LITAN, PROCESSOR_LEVEL=6, SESSIONNAME=Console, ALLUSERSPROFILE=C:\ProgramData, PROCESSOR_ARCHITECTURE=AMD64, PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules;D:\我的软件\办公软件\svnServer\PowerShellModules, SystemDrive=C:, MAVEN_HOME=D:\java软件安装资源汇总\maven建项目\apache-maven-3.3.9-bin\apache-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:\Windows\System32\Drivers\DriverData, ProgramData=C:\ProgramData, ProgramW6432=C:\Program Files, HOMEPATH=\Users\litan, PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 61 Stepping 4, GenuineIntel, ProgramFiles=C:\Program Files, PUBLIC=C:\Users\Public, windir=C:\WINDOWS, =::=::\, ZOOKEEPER_HOME=D:\我的软件\专业软件\zookeeper\zookeeper-3.4.9, LOCALAPPDATA=C:\Users\litan\AppData\Local, USERDOMAIN=LITAN, FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer, LOGONSERVER=\\LITAN, JAVA_HOME=D:\java\java1.8\jdk1.8, ERLANG_HOME=D:\topband\soft\RabbitMQ\erl7.1, OneDrive=C:\Users\litan\OneDrive, =C:=C:\, APPDATA=C:\Users\litan\AppData\Roaming, CommonProgramFiles=C:\Program Files\Common Files, Path=C:\ProgramData\Oracle\Java\javapath;D:\java\oracle\product\11.2.0\dbhome_1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.2 & MySQL Utilities 1.5.2 1.5\Doctrine extensions for PHP\;D:\java\java1.8\jdk1.8\bin;JAVA_HOME%\jre\bin;D:\java\Z_review\apache-tomcat-7.0.67\bin;D:\我的软件;办公软;\svnServer\bin;%ma;en_home%\bin;D:\我的软件\数据库\putty\;C:\Pro;ram Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;";D:\我的软件\专业软件\zookeeper\zookeeper-3.4.9/bin; D:\我的软件\专业软件\zookeeper\zookeeper-3.4.9/conf";D:\java\java1.8\jdk1.8\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files\Git\cmd;C:\WINDOWS\System32\OpenSSH\;D:\java软件安装资源汇总\maven建项目\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;D:\protobufc\bin;C:\Users\litan\AppData\Local\Microsoft\WindowsApps;D:\java软件安装资源汇总\2017-6-25\apache-maven-3.3.9-bin\apache-maven-3.3.9\bin;, OS=Windows_NT, COMPUTERNAME=LITAN, CATALINA_HOME=D:\java\Z_review\apache-tomcat-7.0.67, PROCESSOR_REVISION=3d04, CLASSPATH=.;D:\java\java1.8\jdk1.8\lib;D:\java\java1.8\jdk1.8\lib\tools.jar, CommonProgramW6432=C:\Program Files\Common Files, ComSpec=C:\WINDOWS\system32\cmd.exe, SystemRoot=C:\WINDOWS, TEMP=C:\Users\litan\AppData\Local\Temp, HOMEDRIVE=C:, USERPROFILE=C:\Users\litan, TMP=C:\Users\litan\AppData\Local\Temp, easyplussdk="C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin", 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 c.q.l.core.rolling.TimeBasedRollingPolicy@459718907 - No compression will be used
54 13:13:25,414 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@459718907 - 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 ch.qos.logback.classic.jul.LevelChangePropagator@2f67a4d3 - 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 ch.qos.logback.classic.jul.LevelChangePropagator@2f67a4d3 - 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 ch.qos.logback.classic.jul.LevelChangePropagator@2f67a4d3 - 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 ch.qos.logback.classic.jul.LevelChangePropagator@2f67a4d3 - 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 ch.qos.logback.classic.jul.LevelChangePropagator@2f67a4d3 - 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.springframework.boot.logging.logback.SpringBootJoranConfigurator@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:\worksheet\elk)
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.springframework.web.context.support.GenericWebApplicationContext@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.springframework.web.context.support.GenericWebApplicationContext@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.springframework.web.context.support.GenericWebApplicationContext@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了

posted @ 2018-10-01 14:34  醉逍遥_001  阅读(1733)  评论(0编辑  收藏  举报