欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

logBack配置文件

程序员文章站 2022-07-03 20:06:55
...
依赖的包

<dependency>
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-classic</artifactId>
  <version>1.1.11</version>
</dependency>
<dependency>
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-core</artifactId>
  <version>1.1.11</version>
</dependency>




<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
    <!--appender console 表示会打印到tomcat catalina.log文件中-->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoding>UTF-8</encoding>
        <encoder>
            <pattern>[%d{HH:mm:ss.SSS}][%p][%c{40}][%t] %m%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>DEBUG</level>
        </filter>
    </appender>

    <appender name="mmall" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!--<File>d:/mmalllog/mmall.log</File>-->
        <File>D:\work\server\tomcat\apache-tomcat-8.0.36\logs\mall\mmall.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>D:\work\server\tomcat\apache-tomcat-8.0.36\logs\mall\mmall.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
            <append>true</append>
            <!--表示日志的记录保存天数-->
            <maxHistory>10</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>[%d{HH:mm:ss.SSS}][%p][%c{40}][%t] %m%n</pattern>
        </encoder>
    </appender>


    <!--归档错误日志-->
    <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>D:\work\server\tomcat\apache-tomcat-8.0.36\logs\mall\error.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>D:\work\server\tomcat\apache-tomcat-8.0.36\logs\mall\error.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
            <append>true</append>
            <maxHistory>10</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>[%d{HH:mm:ss.SSS}][%p][%c{40}][%t] %m%n</pattern>
        </encoder>
        <!-- 过略其他级别,在Error中只显示ERROR级别的日志-->
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <!--additivity="false" 不让日志向上继承-->
    <logger name="com.xuzhao.mmall" additivity="false" level="INFO" >
        <appender-ref ref="mmall" />
        <appender-ref ref="console"/>
    </logger>



    <!-- geelynote mybatis log 日志 -->

    <logger name="com.xuzhao.mmall.dao" level="DEBUG"/>

    <logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="DEBUG" >
        <appender-ref ref="console"/>
    </logger>

    <logger name="java.sql.Connection" level="DEBUG">
        <appender-ref ref="console"/>
    </logger>
    <logger name="java.sql.Statement" level="DEBUG">
        <appender-ref ref="console"/>
    </logger>

    <logger name="java.sql.PreparedStatement" level="DEBUG">
        <appender-ref ref="console"/>
    </logger>

    <root level="DEBUG">
        <appender-ref ref="console"/>
        <appender-ref ref="error"/>
    </root>

</configuration>