logback

http://hanhongke123.blog.163.com/blog/static/62223494201241741237345/

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <appender name="FILE"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
         <filter class="ch.qos.logback.classic.filter.ThresholdFilter">   
          <level>INFO</level>   
         </filter> 
        <file>test.log</file>

        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>tests.%i.%d{yyyy-MM-dd}.info.log.zip</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>3</maxIndex>
        </rollingPolicy>

        <triggeringPolicy
            class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>1MB</maxFileSize>
        </triggeringPolicy>
        <encoder>
            <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n
            </pattern>
        </encoder>
    </appender>
    
    <!-- 控制台輸出 -->
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">   
    <filter class="ch.qos.logback.classic.filter.LevelFilter">   
      <level>INFO</level>   
      <onMatch>ACCEPT</onMatch>   
      <onMismatch>DENY</onMismatch>   
    </filter>   
    <encoder>   
      <pattern>   
        %-4relative [%thread] %-5level %logger{30} - %msg%n   
      </pattern>   
    </encoder>   
  </appender>

    <root level="trace">
        <appender-ref ref="FILE" />
        <appender-ref ref="CONSOLE" />
    </root>
</configuration> 
<properties>  
  <logback.version>1.0.11</logback.version>  
  <slf4j.api.version>1.7.5</slf4j.api.version>  
</properties>
<dependencies>  
  <dependency>  
    <groupId>org.slf4j</groupId>  
    <artifactId>slf4j-api</artifactId>  
    <version>${slf4j.api.version}</version>  
  </dependency>  
  <dependency>  
    <groupId>ch.qos.logback</groupId>  
    <artifactId>logback-classic</artifactId>  
    <version>${logback.version}</version>  
  </dependency>  
  <dependency>  
    <groupId>ch.qos.logback</groupId>  
    <artifactId>logback-core</artifactId>  
    <version>${logback.version}</version>  
  </dependency>  
</dependencies>   
package logback;  
  
import org.slf4j.Logger;  
import org.slf4j.LoggerFactory;  
  
public class LogbackDemo {  
    private static Logger log = LoggerFactory.getLogger(LogbackDemo.class);  
    public static void main(String[] args) {  
        
         for(int i=0;i<1000000;i++){
             log.trace("======trace------------------------------------------------");  
                log.debug("======debug------------------------------------------------"); 
                log.info("======info------------------------------------------------"); 
                log.warn("======warn------------------------------------------------");  
                log.error("======error------------------------------------------------");
                System.out.println("還剩"+(1000000-i));
         }  
    }  
}

 

posted @ 2016-08-08 08:07  wind90  阅读(151)  评论(0编辑  收藏  举报