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.access.sift;
15  
16  import java.util.ArrayList;
17  import java.util.List;
18  import java.util.Map;
19  
20  import org.xml.sax.Attributes;
21  
22  import ch.qos.logback.core.joran.action.Action;
23  import ch.qos.logback.core.joran.event.InPlayListener;
24  import ch.qos.logback.core.joran.event.SaxEvent;
25  import ch.qos.logback.core.joran.spi.ActionException;
26  import ch.qos.logback.core.joran.spi.InterpretationContext;
27  
28  public class SiftAction extends Action implements InPlayListener {
29      List<SaxEvent> seList;
30  
31      @Override
32      public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException {
33          seList = new ArrayList<SaxEvent>();
34          ic.addInPlayListener(this);
35      }
36  
37      @Override
38      public void end(InterpretationContext ic, String name) throws ActionException {
39          ic.removeInPlayListener(this);
40          Object o = ic.peekObject();
41          if (o instanceof SiftingAppender) {
42              SiftingAppender siftingAppender = (SiftingAppender) o;
43              Map<String, String> propertyMap = ic.getCopyOfPropertyMap();
44              AppenderFactoryUsingJoran appenderFactory = new AppenderFactoryUsingJoran(seList, siftingAppender.getDiscriminatorKey(), propertyMap);
45              siftingAppender.setAppenderFactory(appenderFactory);
46          }
47      }
48  
49      @Override
50      public void inPlay(SaxEvent event) {
51          seList.add(event);
52      }
53  
54      public List<SaxEvent> getSeList() {
55          return seList;
56      }
57  
58  }