Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.core.sift;
 
This appender serves as the base class for actual SiftingAppenders implemented by the logback-classic and logback-access modules. In a nutshell, a SiftingAppender contains other appenders which it can build dynamically depending on discriminating values supplied by event currently being processed. The built appender is specified as part of a configuration file.

Author(s):
Ceki Gulcu
 
 public abstract class SiftingAppenderBase<E> extends
     AppenderBase<E> {
 
   protected AppenderTracker<E> appenderTracker = new AppenderTrackerImpl<E>();
 
 
   public void setAppenderFactory(AppenderFactoryBase<E> appenderFactory) {
     this. = appenderFactory;
   }
 
   @Override
   public void start() {
     int errors = 0;
     if ( == null) {
       addError("Missing discriminator. Aborting");
       errors++;
     }
     if (!.isStarted()) {
       addError("Discriminator has not started successfully. Aborting");
       errors++;
     }
     if (errors == 0) {
       super.start();
     }
   }
 
   @Override
   public void stop() {
     for (Appender<E> appender : .valueList()) {
       appender.stop();
     }
   }
 
   abstract protected long getTimestamp(E event);
 
   @Override
   protected void append(E event) {
     if (!isStarted()) {
       return;
     }
 
     String discriminatingValue = .getDiscriminatingValue(event);
     long timestamp = getTimestamp(event);
     
     Appender<E> appender = .get(discriminatingValuetimestamp);
     if (appender == null) {
       try {
         appender = .buildAppender(discriminatingValue);
         if (appender == null) {
           appender = buildNOPAppender(discriminatingValue);
         }
         .put(discriminatingValueappendertimestamp);
 
       } catch (JoranException e) {
         addError("Failed to build appender for [" + discriminatingValue + "]",
             e);
         return;
       }
     }
     
     appender.doAppend(event);
   }
 
   public Discriminator<E> getDiscriminator() {
     return ;
   }
  public void setDiscriminator(Discriminator<E> discriminator) {
    this. = discriminator;
  }
  
  
  int nopaWarningCount = 0;
  
  NOPAppender<E> buildNOPAppender(String discriminatingValue) {
      ++;
      addError("Failed to build an appender for discriminating value ["+discriminatingValue+"]");
    }
    NOPAppender<E> nopa = new NOPAppender<E>();
    nopa.setContext();
    nopa.start();
    return nopa;
  }
  // sometime one needs to close a nested appender immediately
  // for example when executing a command which has its own nested appender
  // and the command also cleans up after itself. However, an open file appender
  // will prevent the folder from being deleted
  // see http://www.qos.ch/pipermail/logback-user/2010-March/001487.html
  

Since:
0.9.19
    return ;
  }
  public String getDiscriminatorKey() {
    if ( != null) {
      return .getKey();
    } else {
      return null;
    }
  }
New to GrepCode? Check out our FAQ X