<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="60 seconds" debug="true"> <!-- 模塊名稱, 影響日誌配置名,日誌文件名 --> <property name="appName" value="PersonalJiJin"/> <property name="logMaxSize" valule="100MB"/> <!--rootPath 日誌路徑,這裏是相對路徑,web項目eclipse下會輸出到eclipse的安裝目錄下,若是部署到linux上的tomcat下,會輸出到tomcat/bin目錄 下 --> <property name="rootPath" value="/home/wasadmin/logs"/> <contextName>${appName}</contextName> <!--控制檯輸出 --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss}|%t|%p| %m |%logger:%L%n</pattern> </encoder> </appender> <appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 設置日誌不超過${logMaxSize}時的保存路徑,注意若是 是web項目會保存到Tomcat的bin目錄 下 --> <file>${rootPath}/${appName}/debug/${appName}-dlog.log</file> <!-- 滾動記錄文件,先將日誌記錄到指定文件,當符合某個條件時,將日誌記錄到其餘文件。--> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${rootPath}/${appName}/debug/${appName}-dlog-%d{yyyy-MM-dd}-%d.log</fileNamePattern> <maxHistory>30</maxHistory> <!-- 當天的日誌大小 超過${logMaxSize}時,壓縮日誌並保存 --> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>10MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <!-- 日誌輸出的文件的格式 --> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss}|%t|%p| %m |%logger:%L%n</pattern> <charset>UTF-8</charset> </encoder> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>DEBUG</level> </filter> </appender> <appender name="INFO" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${rootPath}/${appName}/info/${appName}-ilog.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${rootPath}/${appName}/all/${appName}-ilog-%d{yyyy-MM-dd}-%i.log</fileNamePattern> <maxHistory>30</maxHistory> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>10MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss}|%t|%p| %m |%logger:%L%n</pattern> <charset>UTF-8</charset> </encoder> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>INFO</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${rootPath}/${appName}/error/${appName}-elog.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${rootPath}/${appName}/all/${appName}-elog-%d{yyyy-MM-dd}-%e.log</fileNamePattern> <maxHistory>30</maxHistory> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>10MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss}|%t|%p| %m |%logger:%L%n</pattern> <charset>UTF-8</charset> </encoder> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>ERROR</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> </appender> <!-- 爲某個包下的全部類的指定Appender 這裏也能夠指定類名稱例如:com.aa.bb.ClassName,下面還有另外一種寫法,就是涉及到name="關鍵包的日誌輸出級別" --> <!-- <logger name="com.lin" additivity="false"> --> <!-- <level value="debug" /> --> <!-- <appender-ref ref="stdout" /> --> <!-- <appender-ref ref="file" /> --> <!-- </logger> --> <logger name="jdbc" level="INFO"/> <logger name="org" level="INFO"/> <logger name="net" level="INFO"/> <logger name="sql" level="INFO"/> <logger name="java.sql" level="INFO"/> <logger name="javax" level="INFO"/> <!--日誌的輸出級別由低到高(越來問題越嚴重)trace->debug->info->warn->error --> <!-- root將級別爲DEBUG及大於DEBUG的日誌信息交給已經配置好的name='STDOUT'的appender處理,將信息打印到控制檯-Console --> <root level="DEBUG"> <!-- appender-ref標識這個appender將會添加到本應用的日誌系統中 --> <appender-ref ref="STDOUT"/> <appender-ref ref="INFO"/> <appender-ref ref="DEBUG"/> <appender-ref ref="ERROR"/> </root> </configuration>