SpringMVC中配置分离,配置logback

pom.xml


<dependency>
   <groupId>ch.qos.logbackgroupId>
    <artifactId>logback-classicartifactId>
     <version>${logback.version}version>
<exclusions>
    <exclusion>
     <artifactId>slf4j-apiartifactId>
    <groupId>org.slf4jgroupId>
exclusion>
exclusions>

dependency>
<dependency>
    <groupId>ch.qos.logbackgroupId>
    <artifactId>logback-coreartifactId>
    <version>${logback.version}version>
dependency>
<dependency>
    <groupId>ch.qos.logbackgroupId>
    <artifactId>logback-accessartifactId>
    <version>${logback.version}version>
dependency>
<dependency>
    <groupId>org.logback-extensionsgroupId>
    <artifactId>logback-ext-springartifactId>
    <version>0.1.4version>
dependency>

 

 


logback.xml

<configuration scan="true" scanPeriod="60 seconds">      
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>infolevel>        
        filter>
        <encoder>
            <pattern>[lf-1][edums][%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5level][%thread][%file:%line] - %msg%npattern>
        encoder>
    appender>


    <appender name="ERROR_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/home/logs/edums/edums-error.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>/home/logs/edums/edums-error.log.%d{yyyy-MM-dd}fileNamePattern>
            <maxHistory>10maxHistory>
        rollingPolicy>
        <encoder>
            <pattern>[lf-1][edums][%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5level][%thread][%file:%line] - %msg%npattern>
            <charset>UTF-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>warnlevel>        
        filter>
    appender>


    <appender name="NORMAL_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/home/logs/edums/edums.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>/home/logs/edums/edums.log.%d{yyyyMMdd}fileNamePattern>
            <maxHistory>10maxHistory>
        rollingPolicy>
        <encoder>
            <pattern>[lf-1][edums][%d{yyyy-MM-dd HH:mm:ss.SSS}][%-5level][%thread][%file:%line] - %msg%npattern>
            <charset>UTF-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>infolevel>        
        filter>
    appender>


    


    <root level="debug">                
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="ERROR_LOG"/>
        <appender-ref ref="NORMAL_LOG"/>
    root

>

 

web.xml

<context-param>
<param-name>logbackConfigLocationparam-name>
<param-value>file:D:\home\conf\edums\logback.xmlparam-value>
context-param>

      

<listener>
<listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListenerlistener-class>

listener>

  

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
listener>

 

 //顺序颠倒可能导致异常的log打印

  

                                                                               微信公众号: 

                                               SpringMVC中配置分离,配置logback_第1张图片

                                                                             JAVA程序猿成长之路

                              分享资源,记录程序猿成长点滴。专注于Java,Spring,SpringBoot,SpringCloud,分布式,微服务。

你可能感兴趣的:(SpringMVC中配置分离,配置logback)