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.classic.sift;
 
 
 import java.util.Map;

MDCBasedDiscriminator essentially returns the value mapped to an MDC key. If the said value is null, then a default value is returned.

Both Key and the DefaultValue are user specified properties.

Author(s):
Ceki Gülcü
 
 public class MDCBasedDiscriminator extends ContextAwareBase implements
         Discriminator<ILoggingEvent> {
 
   private String key;
   private String defaultValue;
   private boolean started = false;

  
Return the value associated with an MDC entry designated by the Key property. If that value is null, then return the value assigned to the DefaultValue property.
 
     // http://jira.qos.ch/browse/LBCLASSIC-213
     Map<StringStringmdcMap = event.getMDCPropertyMap();
     if (mdcMap == null) {
       return ;
     }
     String mdcValue = mdcMap.get();
     if (mdcValue == null) {
       return ;
     } else {
       return mdcValue;
     }
   }
 
   public boolean isStarted() {
     return ;
   }
 
   public void start() {
     int errors = 0;
     if (OptionHelper.isEmpty()) {
       errors++;
       addError("The \"Key\" property must be set");
     }
     if (OptionHelper.isEmpty()) {
       errors++;
       addError("The \"DefaultValue\" property must be set");
     }
     if (errors == 0) {
        = true;
     }
   }
 
   public void stop() {
      = false;
   }
 
   public String getKey() {
     return ;
   }
 
   public void setKey(String key) {
     this. = key;
   }

  
 
   public String getDefaultValue() {
     return ;
   }

  
The default MDC value in case the MDC is not set for mdcKey.

For example, if Key is set to the value "someKey", and the MDC is not set for "someKey", then this appender will use the default value, which you can set with the help of this method.

Parameters:
defaultValue
  public void setDefaultValue(String defaultValue) {
    this. = defaultValue;
  }
New to GrepCode? Check out our FAQ X