1. 基础模板
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%thread] %logger{35} - %msg%n</pattern>
</layout>
</appender>
<appender name="logFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/ace/gjh.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/var/log/ace/gjh.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%thread] %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="stdout"/>
<appender-ref ref="logFile"/>
</root>
<logger name="cool.gjh" level="INFO"/>
</configuration>
2. 升级模板-日志分级别分类保存
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%thread] %logger{35} - %msg%n</pattern>
</layout>
</appender>
<appender name="logFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/ace/gjh.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/var/log/ace/gjh.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%thread] %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<appender name="logFileInfo" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/ace/info/gjh-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.TimeBasedRollingPolicy">
<fileNamePattern>/var/log/ace/info/gjh-info.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%thread] %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<appender name="logFileWarn" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/ace/warn/gjh-warn.log</file>
<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.TimeBasedRollingPolicy">
<fileNamePattern>/var/log/ace/warn/gjh-warn.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%thread] %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<appender name="logFileError" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/ace/error/gjh-error.log</file>
<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.TimeBasedRollingPolicy">
<fileNamePattern>/var/log/ace/error/gjh-error.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%thread] %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="logFile"/>
<appender-ref ref="logFileInfo"/>
<appender-ref ref="logFileWarn"/>
<appender-ref ref="logFileError"/>
<appender-ref ref="stdout"/>
</root>
<logger name="cool.gjh" additivity="false">
<appender-ref ref="logFile"/>
<appender-ref ref="logFileInfo"/>
<appender-ref ref="logFileWarn"/>
<appender-ref ref="logFileError"/>
<appender-ref ref="stdout"/>
</logger>
</configuration>