logback日志配置文件

Posted f-society

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了logback日志配置文件相关的知识,希望对你有一定的参考价值。

application.properties

application.properties

 

 

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <!-- 定义log文件的目录 -->
  <property name="LOG_HOME" value="log"></property>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <!-- %.-1level 只显示信息级别的首字母,%-5level 左对齐显示信息级别全称 -->
      <Pattern>[%dateyyyy-MM-dd HH:mm:ss] [%-5level] [%logger:%line] --%mdcclient %msg%n</Pattern>
    </encoder>
  </appender>
  <appender name="TRACE_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>$LOG_HOME/trace.log</file>
    <append>true</append>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      <fileNamePattern>$LOG_HOME/logs/trace.%dyyyy-MM-ddssSSS.%i.log.zip</fileNamePattern>
      <maxFileSize>20MB</maxFileSize>
      <maxHistory>7</maxHistory>
      <totalSizeCap>20GB</totalSizeCap>
    </rollingPolicy>
    <encoder>
      <pattern>[%dateyyyy-MM-dd HH:mm:ss] [%-5level] [%logger:%line] --%mdcclient %msg%n</pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
      <level>TRACE</level>
      <onMatch>ACCEPT</onMatch>
      <onMismatch>DENY</onMismatch>
    </filter>
  </appender>
  <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>$LOG_HOME/info.log</file>
    <append>true</append>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      <fileNamePattern>$LOG_HOME/logs/info.%dyyyy-MM-dd.%i.log.zip</fileNamePattern>
      <maxFileSize>20MB</maxFileSize>
      <maxHistory>7</maxHistory>
      <totalSizeCap>20GB</totalSizeCap>
    </rollingPolicy>
    <encoder>
      <pattern>[%dateyyyy-MM-dd HH:mm:ss] [%-5level] [%logger:%line] --%mdcclient %msg%n</pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
      <level>INFO</level>
      <onMatch>ACCEPT</onMatch>
      <onMismatch>DENY</onMismatch>
    </filter>
  </appender>
  <appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>$LOG_HOME/debug.log</file>
    <append>true</append>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      <fileNamePattern>$LOG_HOME/logs/debug.%dyyyy-MM-dd.%i.log.zip</fileNamePattern>
      <maxFileSize>20MB</maxFileSize>
      <maxHistory>7</maxHistory>
      <totalSizeCap>20GB</totalSizeCap>
    </rollingPolicy>
    <encoder>
      <pattern>[%dateyyyy-MM-dd HH:mm:ss] [%-5level] [%logger:%line] --%mdcclient %msg%n</pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
      <level>DEBUG</level>
      <onMatch>ACCEPT</onMatch>
      <onMismatch>DENY</onMismatch>
    </filter>
  </appender>
  <appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>$LOG_HOME/warn.log</file>
    <append>true</append>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      <fileNamePattern>$LOG_HOME/logs/warn.%dyyyy-MM-dd.%i.log.zip</fileNamePattern>
      <maxFileSize>20MB</maxFileSize>
      <maxHistory>7</maxHistory>
      <totalSizeCap>20GB</totalSizeCap>
    </rollingPolicy>
    <encoder>
      <pattern>[%dateyyyy-MM-dd HH:mm:ss] [%-5level] [%logger:%line] --%mdcclient %msg%n</pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
      <level>WARN</level>
      <onMatch>ACCEPT</onMatch>
      <onMismatch>DENY</onMismatch>
    </filter>
  </appender>
  <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>$LOG_HOME/error.log</file>
    <append>true</append>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      <fileNamePattern>$LOG_HOME/logs/error.%dyyyy-MM-dd.%i.log.zip</fileNamePattern>
      <maxFileSize>20MB</maxFileSize>
      <maxHistory>7</maxHistory>
      <totalSizeCap>20GB</totalSizeCap>
    </rollingPolicy>
    <encoder>
      <pattern>[%dateyyyy-MM-dd HH:mm:ss] [%-5level] [%logger:%line] --%mdcclient %msg%n</pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
      <level>ERROR</level>
      <onMatch>ACCEPT</onMatch>
      <onMismatch>DENY</onMismatch>
    </filter>
  </appender>
  <appender name="ALL_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>$LOG_HOME/all.log</file>
    <append>true</append>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      <fileNamePattern>$LOG_HOME/logs/all.%dyyyy-MM-dd.%i.log.zip</fileNamePattern>
      <maxFileSize>100MB</maxFileSize>
      <maxHistory>7</maxHistory>
      <totalSizeCap>50GB</totalSizeCap>
    </rollingPolicy>
    <encoder>
      <pattern>[%dateyyyy-MM-dd HH:mm:ss] [%-5level] [%logger:%line] --%mdcclient %msg%n</pattern>
    </encoder>
  </appender>
  <root level="INFO">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="TRACE_FILE" />
    <appender-ref ref="INFO_FILE" />
    <appender-ref ref="DEBUG_FILE" />
    <appender-ref ref="WARN_FILE" />
    <appender-ref ref="ERROR_FILE" />
    <appender-ref ref="ALL_FILE" />
  </root>
</configuration>

 

以上是关于logback日志配置文件的主要内容,如果未能解决你的问题,请参考以下文章

logback.xml参考配置模板

logback配置文件详解

如何在logback日志配置文件中配置相对路径

Java Logback配置文件这么写,还愁不会整理日志?

logback的日志配置文件

logback配置文件配置日志