SpringMVC中配置分离,配置logback
pom.xml
<!-- LOGGING begin --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>${logback.version}</version> <exclusions> <exclusion> <artifactId>slf4j-api</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> <!--<scope>test</scope> --> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>${logback.version}</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-access</artifactId> <version>${logback.version}</version> </dependency> <dependency> <groupId>org.logback-extensions</groupId> <artifactId>logback-ext-spring</artifactId> <version>0.1.4</version> </dependency> <!-- LOGGING end -->
logback.xml
<configuration scan="true" scanPeriod="60 seconds"> <!-- Auto Scan config file --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>info</level> <!-- only show error msg in stdout --> </filter> <encoder> <pattern>[lf-1][edums][%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5level][%thread][%file:%line] - %msg%n</pattern> </encoder> </appender> <appender name="ERROR_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>/home/logs/edums/edums-error.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>/home/logs/edums/edums-error.log.%d{yyyy-MM-dd}</fileNamePattern> <maxHistory>10</maxHistory> </rollingPolicy> <encoder> <pattern>[lf-1][edums][%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5level][%thread][%file:%line] - %msg%n</pattern> <charset>UTF-8</charset> </encoder> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>warn</level> <!-- only log warn/error msg --> </filter> </appender> <appender name="NORMAL_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>/home/logs/edums/edums.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>/home/logs/edums/edums.log.%d{yyyyMMdd}</fileNamePattern> <maxHistory>10</maxHistory> </rollingPolicy> <encoder> <pattern>[lf-1][edums][%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5level][%thread][%file:%line] - %msg%n</pattern> <charset>UTF-8</charset> </encoder> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>info</level> <!-- only log warn/error msg --> </filter> </appender> <!-- #################################################################### --> <root level="debug"> <!-- level=trace/debug/info/warn/error/all/off --> <appender-ref ref="STDOUT"/> <appender-ref ref="ERROR_LOG"/> <appender-ref ref="NORMAL_LOG"/> </root </configuration>
web.xml
<context-param> <param-name>logbackConfigLocation</param-name> <param-value>file:D:\home\conf\edums\logback.xml</param-value> </context-param> <!-- 顺序1 --> <listener> <listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class> </listener> <!-- 顺序2--> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
//顺序颠倒可能导致异常的log打印
微信公众号