logback笔记2

logback官网地址:https://logback.qos.ch/manual/appenders.html

第4章

Logback delegates the task of writing a logging event to components called appenders. Appenders must implement the ch.qos.logback.core.Appender interface. The salient methods of this interface are summarized below:

package ch.qos.logback.core;
  
import ch.qos.logback.core.spi.ContextAware;
import ch.qos.logback.core.spi.FilterAttachable;
import ch.qos.logback.core.spi.LifeCycle;
  

public interface Appender<E> extends LifeCycle, ContextAware, FilterAttachable {

  public String getName();
  public void setName(String name);
  void doAppend(E event);
  
}

Example: Sample configuration for SizeAndTimeBasedFNATP (logback-examples/src/main/resources/chapters/appenders/conf/logback-sizeAndTime.xml)

View as .groovy

   name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
    mylog.txt
     class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      
      mylog-%d{yyyy-MM-dd}.%i.txt
       
       100MB    
       60
       20GB
    
    
      %msg%n
    
  


   level="DEBUG">
     ref="ROLLING" />
  

Note the "%i" conversion token in addition to "%d". Both the %i and %d tokens are mandatory. Each time the current log file reaches maxFileSize before the current time period ends, it will be archived with an increasing index, starting at 0.

Size and time based archiving supports deletion of old archive files. You need to specify the number of periods to preserve with the maxHistory property. When your application is stopped and restarted, logging will continue at the correct location, i.e. at the largest index number for the current period.


你可能感兴趣的:(日志)