配置文件如下
<?xml version="1.0" encoding="UTF-8"?> <configuration debug="false" scan="false"> <!-- 定义日志文件名称,与工程名一致 --> <property name="APP_NAME" value="PAS_Backstage1" /> <!-- 定义日志的根目录 --> <property name="LOG_HOME" value="../logs1" /> <!-- 控制台输出设置 --> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}-%msg%n </pattern> </layout> </encoder> </appender> <!-- 正常文件输出设置 --> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>${LOG_HOME}/${APP_NAME}.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <FileNamePattern>${LOG_HOME}/${APP_NAME}/${APP_NAME}-%d{yyyy-MM-dd}-%i.zip </FileNamePattern> <maxFileSize>50MB</maxFileSize> <maxHistory>365</maxHistory> <totalSizeCap>20GB</totalSizeCap> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> </encoder> </appender> <!-- 异常文件输出设置,将异常堆栈另外保存一份到单独的文件中,方便查找 --> <appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>${LOG_HOME}/${APP_NAME}.error.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <FileNamePattern>${LOG_HOME}/${APP_NAME}/${APP_NAME}.error-%d{yyyy-MM-dd}-%i.zip </FileNamePattern> <maxFileSize>50MB</maxFileSize> <maxHistory>365</maxHistory> <totalSizeCap>20GB</totalSizeCap> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> </encoder> <filter class="ch.qos.logback.classic.filter.LevelFilter"><!-- 只打印错误日志 --> <level>ERROR</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <filter class="ch.qos.logback.classic.filter.LevelFilter"><!-- 只打印警告日志 --> <level>WARN</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <!-- Spring framework logger --> <logger name="org.springframework" level="info"></logger> <!-- com.ceiec --> <logger name="com.ceiec" level="info"></logger> <logger name="dao" level="debug"/> <root level="info"> <appender-ref ref="CONSOLE" /> <appender-ref ref="FILE" /> <appender-ref ref="FILE_ERROR" /> </root> </configuration>
将项目打包为war包后,放入webapps下,生成的日志文件在如下位置:
当我把配置调整如下:
<property name="LOG_HOME" value="logs2" />
生成的日志在: