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.core.sift;
15  
16  import java.util.List;
17  import java.util.Map;
18  
19  import ch.qos.logback.core.Appender;
20  import ch.qos.logback.core.Context;
21  import ch.qos.logback.core.joran.event.SaxEvent;
22  import ch.qos.logback.core.joran.spi.JoranException;
23  
24  /**
25   * Builds new appenders dynamically by running SiftingJoranConfigurator instance,
26   * a custom configurator tailored for the contents of the sift element.
27   * @param <E>
28   */
29  public abstract class AbstractAppenderFactoryUsingJoran<E> implements AppenderFactory<E> {
30  
31      final List<SaxEvent> eventList;
32      protected String key;
33      protected Map<String, String> parentPropertyMap;
34  
35      protected AbstractAppenderFactoryUsingJoran(List<SaxEvent> eventList, String key, Map<String, String> parentPropertyMap) {
36          this.eventList = removeSiftElement(eventList);
37          this.key = key;
38          this.parentPropertyMap = parentPropertyMap;
39  
40      }
41  
42      List<SaxEvent> removeSiftElement(List<SaxEvent> eventList) {
43          return eventList.subList(1, eventList.size() - 1);
44      }
45  
46      public abstract SiftingJoranConfiguratorBase<E> getSiftingJoranConfigurator(String k);
47  
48      public Appender<E> buildAppender(Context context, String discriminatingValue) throws JoranException {
49          SiftingJoranConfiguratorBase<E> sjc = getSiftingJoranConfigurator(discriminatingValue);
50          sjc.setContext(context);
51          sjc.doConfigure(eventList);
52          return sjc.getAppender();
53      }
54  
55      public List<SaxEvent> getEventList() {
56          return eventList;
57      }
58  
59  }