zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
    <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
    <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
    <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
    <property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
    <property name="FILE_LOG_PATTERN" value="${FILE_LOG_PATTERN:-%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} ${PID:- } --- [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
 
    <property name="LOG_HOME" value="./logs" />
 
    <springProperty scope="context" name="port" source="server.port"/>
    <springProperty scope="context" name="appName" source="spring.application.name"/>
 
    <!-- 控制台输出 -->
    <appender name="CONSOLE_LOG" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
        </encoder>
    </appender>
 
    <!-- 按照每天生成日志文件 -->
    <appender name="DEBUG_LOG"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--     日志文件输出的文件名 -->
            <FileNamePattern>${LOG_HOME}/${port}/%d{yyyy-MM-dd}/${appName}-debug.log</FileNamePattern>
            <!-- 日志文件保留天数 -->
            <MaxHistory>10</MaxHistory>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${FILE_LOG_PATTERN}</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>DEBUG</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10MB</MaxFileSize>
        </triggeringPolicy>
    </appender>
 
    <appender name="ERROR_LOG"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${LOG_HOME}/${port}/%d{yyyy-MM-dd}/${appName}-error.log</FileNamePattern>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${FILE_LOG_PATTERN}</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>10MB</MaxFileSize>
        </triggeringPolicy>
    </appender>
 
    <logger name="com.changhong.epc"                                     />
    <logger name="com.apache.ibatis"                                     />
    <logger name="org.apache.http"                        level="ERROR"    />
    <logger name="java.sql"                                             />
    <logger name="org.springframework"                     level="INFO"     />
    <logger name="com.ibatis"                                             />
    <logger name="com.ibatis.common.jdbc.SimpleDataSource"                 />
    <logger name="com.ibatis.common.jdbc.ScriptRunner"                     />
    <logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate"     />
    <logger name="java.sql.Connection"                                     />
    <logger name="java.sql.Statement"                                     />
    <logger name="java.sql.PreparedStatement"                             />
 
    <springProfile name="test">
        <root level="DEBUG">
            <appender-ref ref="CONSOLE_LOG" />
            <appender-ref ref="DEBUG_LOG" />
            <appender-ref ref="ERROR_LOG" />
        </root>
    </springProfile>
 
    <springProfile name="formal">
        <root level="ERROR">
            <appender-ref ref="CONSOLE_LOG" />
            <appender-ref ref="DEBUG_LOG" />
            <appender-ref ref="ERROR_LOG" />
        </root>
    </springProfile>
</configuration>