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.joran;
15  
16  import ch.qos.logback.access.PatternLayout;
17  import ch.qos.logback.access.PatternLayoutEncoder;
18  import ch.qos.logback.access.boolex.JaninoEventEvaluator;
19  import ch.qos.logback.access.joran.action.ConfigurationAction;
20  import ch.qos.logback.access.joran.action.EvaluatorAction;
21  import ch.qos.logback.access.sift.SiftAction;
22  import ch.qos.logback.access.spi.IAccessEvent;
23  import ch.qos.logback.core.AppenderBase;
24  import ch.qos.logback.core.UnsynchronizedAppenderBase;
25  import ch.qos.logback.core.filter.EvaluatorFilter;
26  import ch.qos.logback.core.joran.JoranConfiguratorBase;
27  import ch.qos.logback.core.joran.action.AppenderRefAction;
28  import ch.qos.logback.core.joran.action.IncludeAction;
29  import ch.qos.logback.core.joran.action.NOPAction;
30  import ch.qos.logback.core.joran.conditional.ElseAction;
31  import ch.qos.logback.core.joran.conditional.IfAction;
32  import ch.qos.logback.core.joran.conditional.ThenAction;
33  import ch.qos.logback.core.joran.spi.DefaultNestedComponentRegistry;
34  import ch.qos.logback.core.joran.spi.ElementSelector;
35  import ch.qos.logback.core.joran.spi.RuleStore;
36  import ch.qos.logback.core.net.ssl.SSLNestedComponentRegistryRules;
37  
38  /**
39   * This JoranConfiguratorclass adds rules specific to logback-access.
40   *
41   * @author Ceki Gülcü
42   */
43  public class JoranConfigurator extends JoranConfiguratorBase<IAccessEvent> {
44  
45      @Override
46      public void addInstanceRules(RuleStore rs) {
47          super.addInstanceRules(rs);
48  
49          rs.addRule(new ElementSelector("configuration"), new ConfigurationAction());
50          rs.addRule(new ElementSelector("configuration/appender-ref"), new AppenderRefAction<IAccessEvent>());
51  
52          rs.addRule(new ElementSelector("configuration/appender/sift"), new SiftAction());
53          rs.addRule(new ElementSelector("configuration/appender/sift/*"), new NOPAction());
54  
55          rs.addRule(new ElementSelector("configuration/evaluator"), new EvaluatorAction());
56  
57          // add if-then-else support
58          rs.addRule(new ElementSelector("*/if"), new IfAction());
59          rs.addRule(new ElementSelector("*/if/then"), new ThenAction());
60          rs.addRule(new ElementSelector("*/if/then/*"), new NOPAction());
61          rs.addRule(new ElementSelector("*/if/else"), new ElseAction());
62          rs.addRule(new ElementSelector("*/if/else/*"), new NOPAction());
63  
64          rs.addRule(new ElementSelector("configuration/include"), new IncludeAction());
65      }
66  
67      @Override
68      protected void addDefaultNestedComponentRegistryRules(DefaultNestedComponentRegistry registry) {
69          registry.add(AppenderBase.class, "layout", PatternLayout.class);
70          registry.add(EvaluatorFilter.class, "evaluator", JaninoEventEvaluator.class);
71  
72          registry.add(AppenderBase.class, "encoder", PatternLayoutEncoder.class);
73          registry.add(UnsynchronizedAppenderBase.class, "encoder", PatternLayoutEncoder.class);
74          SSLNestedComponentRegistryRules.addDefaultNestedComponentRegistryRules(registry);
75      }
76  
77  }