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.pattern;
public class MDCConverter extends ClassicConverter {
  private static final String EMPTY_STRING = "";
  public void start() {
     = getFirstOption();
    super.start();
  }
  public void stop() {
     = null;
    super.stop();
  }
  public String convert(ILoggingEvent event) {
    Map<StringStringmdcPropertyMap = event.getMDCPropertyMap();
    if (mdcPropertyMap == null) {
      return ;
    }
    if ( == null) {
      return outputMDCForAllKeys(mdcPropertyMap);
    } else {
      String value = event.getMDCPropertyMap().get();
      if (value != null) {
        return value;
      } else {
        return ;
      }
    }
  }

  
if no key is specified, return all the values present in the MDC, in the format "k1=v1, k2=v2, ..."
  private String outputMDCForAllKeys(Map<StringStringmdcPropertyMap) {
    StringBuilder buf = new StringBuilder();
    boolean first = true;
    for (Map.Entry<StringStringentry : mdcPropertyMap.entrySet()) {
      if (first) {
        first = false;
      } else {
        buf.append(", ");
      }
      //format: key0=value0, key1=value1
      buf.append(entry.getKey()).append('=').append(entry.getValue());
    }
    return buf.toString();
  }
New to GrepCode? Check out our FAQ X