View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.classic.pattern;
15  
16  import java.util.List;
17  
18  import org.slf4j.Marker;
19  
20  import ch.qos.logback.classic.spi.ILoggingEvent;
21  
22  /**
23   * Return the event's marker value(s).
24   * 
25   * @author Sébastien Pennec
26   */
27  public class MarkerConverter extends ClassicConverter {
28  
29      private static String EMPTY = "";
30  
31      public String convert(ILoggingEvent le) {
32          List<Marker> markers = le.getMarkerList();
33          if (markers == null || markers.isEmpty()) {
34              return EMPTY;
35          }
36          int size = markers.size();
37  
38          if (size == 1)
39              return markers.get(0).toString();
40  
41          StringBuffer buf = new StringBuffer(32);
42          for (int i = 0; i < size; i++) {
43              if (i != 0)
44                  buf.append(' ');
45              Marker m = markers.get(i);
46              buf.append(m.toString());
47          }
48          return buf.toString();
49  
50      }
51  
52  }