logback.xml 7.86 KB
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <property name="log.path" value="/WMSlog" />
    <property name="log.pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
    <!--<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender" />-->
    <property resource="application-druid.properties" />
    <property name="dataSource" value="${spring.datasource.type}" />
    <property name="driverClassName" value="${spring.datasource.driverClassName}" />
    <property name="url" value="${spring.datasource.druid.master.url}" />
    <property name="username" value="${spring.datasource.druid.master.username}" />
    <property name="password" value="${spring.datasource.druid.master.password}" />

    <!-- 控制台输出 -->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <charset>UTF-8</charset>
            <pattern>${log.pattern}</pattern>
        </encoder>
        <!--<filter class="ch.qos.logback.classic.filter.LevelFilter">-->
        <!--<level>INFO</level>-->
        <!--<onMatch>ACCEPT</onMatch>-->
        <!--<onMismatch>DENY</onMismatch>-->
        <!--</filter>-->
    </appender>

    <!--
    TimeBasedRollingPolicy
    SizeBasedTriggeringPolicy
    官方文档说明当这2个配置同时存在时存在冲突
    http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedFNATP
    官方推荐配置如下:
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  rollover daily
<fileNamePattern>mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
each file should be at most 100MB, keep 60 days worth of history, but at most 20GB
<maxFileSize>100MB</maxFileSize>
<maxHistory>60</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>

    -->

    <!-- 系统日志输出 只记录DEBUG级别-->
    <appender name="file_debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>DEBUG</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/sys-debug/sys-debug.%d{yyyyMMdd}-%i.log</fileNamePattern>
            <!-- 文件大小触发重写新文件 -->
            <maxFileSize>20MB</maxFileSize>
            <!-- 日志最大的历史 30天 -->
            <maxHistory>30</maxHistory>
            <!--最多10GB-->
            <totalSizeCap>20GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>${log.pattern}</pattern>
        </encoder>
    </appender>

    <!-- 系统日志输出 只记录INFO级别-->
    <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!--<file>${log.path}/sys-info/sys-info.log</file>-->
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFO</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- 按天回滚 daily -->
            <fileNamePattern>${log.path}/sys-info/sys-info.%d{yyyyMMdd}-%i.log</fileNamePattern>
            <!-- 文件大小触发重写新文件 -->
            <maxFileSize>20MB</maxFileSize>
            <!-- 日志最大的历史 30天 -->
            <maxHistory>30</maxHistory>
            <!--最多2GB-->
            <totalSizeCap>5GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>${log.pattern}</pattern>
        </encoder>
        <!--<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            &lt;!&ndash; 文件大小触发重写新文件 &ndash;&gt;
            <maxFileSize>20MB</maxFileSize>
        </triggeringPolicy>-->
    </appender>

    <!-- 系统日志输出 只记录WARN级别-->
    <appender name="file_warn" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>WARN</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!-- 按天回滚 daily -->
            <fileNamePattern>${log.path}/sys-warn/sys-warn.%d{yyyyMMdd}-%i.log</fileNamePattern>
            <!-- 文件大小触发重写新文件 -->
            <maxFileSize>20MB</maxFileSize>
            <!-- 日志最大的历史 30天 -->
            <maxHistory>30</maxHistory>
            <!--最多2GB-->
            <totalSizeCap>10GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>${log.pattern}</pattern>
        </encoder>
        <!--<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            &lt;!&ndash; 文件大小触发重写新文件 &ndash;&gt;
            <maxFileSize>20MB</maxFileSize>
        </triggeringPolicy>-->
    </appender>

    <!-- 系统日志输出 只记录ERROR级别-->
    <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/sys-error/sys-error.%d{yyyyMMdd}-%i.log</fileNamePattern>
            <!-- 文件大小触发重写新文件 -->
            <maxFileSize>20MB</maxFileSize>
            <!-- 日志最大的历史 30天 -->
            <maxHistory>30</maxHistory>
            <!--最多2GB-->
            <totalSizeCap>5GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>${log.pattern}</pattern>
        </encoder>
        <!--<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            &lt;!&ndash; 文件大小触发重写新文件 &ndash;&gt;
            <maxFileSize>20MB</maxFileSize>
        </triggeringPolicy>-->
    </appender>

    <!--将日志传到数据库 表logging_event-->
    <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
        <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
            <dataSource class="${dataSource}">
                <driverClassName>${driverClassName}</driverClassName>
                <url>${url}</url>
                <username>${username}</username>
                <password>${password}</password>
            </dataSource>
        </connectionSource>

        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <!-- 显示形成的sql、使用的参数、结果集 -->
    <!--<logger name="java.sql" level="DEBUG" >-->
    <!--<appender-ref ref="console" />-->
    <!--<appender-ref ref="file_info" />-->
    <!--</logger>-->

    <!--<logger name="org.springframework.jdbc" level="DEBUG">-->
    <!--<appender-ref ref="console" />-->
    <!--<appender-ref ref="file_info" />-->
    <!--</logger>-->
    <!--<logger name="com.huaheng" level="debug" />-->

    <!--系统操作日志-->
    <root level="INFO">
        <appender-ref ref="console" />
        <appender-ref ref="file_debug"/>
        <appender-ref ref="file_info" />
        <appender-ref ref="file_warn"/>
        <appender-ref ref="file_error"/>
        <appender-ref ref="DB"/>
        <!--<appender-ref ref="ROLLING" />-->
    </root>


    <!--系统用户操作日志-->
    <!--<logger name="sys-user" level="debug">-->
    <!--<appender-ref ref="sys-user"/>-->
    <!--</logger>-->
</configuration>