View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2011, 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  
17  import ch.qos.logback.access.PatternLayout;
18  import ch.qos.logback.access.PatternLayoutEncoder;
19  import ch.qos.logback.access.boolex.JaninoEventEvaluator;
20  import ch.qos.logback.access.joran.action.ConfigurationAction;
21  import ch.qos.logback.access.joran.action.EvaluatorAction;
22  import ch.qos.logback.access.sift.SiftAction;
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.Pattern;
35  import ch.qos.logback.core.joran.spi.RuleStore;
36  
37  
38  
39  /**
40   * This JoranConfiguratorclass adds rules specific to logback-access.
41   *
42   * @author Ceki Gülcü
43   */
44  public class JoranConfigurator extends JoranConfiguratorBase {
45  
46    @Override
47    public void addInstanceRules(RuleStore rs) {
48      super.addInstanceRules(rs);
49      
50      rs.addRule(new Pattern("configuration"), new ConfigurationAction());
51      rs.addRule(new Pattern("configuration/appender-ref"), new AppenderRefAction());
52      
53      rs.addRule(new Pattern("configuration/appender/sift"), new SiftAction());
54      rs.addRule(new Pattern("configuration/appender/sift/*"), new NOPAction());
55      
56      rs.addRule(new Pattern("configuration/evaluator"), new EvaluatorAction());
57  
58      // add if-then-else support
59      rs.addRule(new Pattern("*/if"), new IfAction());
60      rs.addRule(new Pattern("*/if/then"), new ThenAction());
61      rs.addRule(new Pattern("*/if/then/*"), new NOPAction());
62      rs.addRule(new Pattern("*/if/else"), new ElseAction());
63      rs.addRule(new Pattern("*/if/else/*"), new NOPAction());
64  
65      rs.addRule(new Pattern("configuration/include"), new IncludeAction());
66    }
67  
68    @Override
69    protected void addDefaultNestedComponentRegistryRules(
70        DefaultNestedComponentRegistry registry) {
71      registry.add(AppenderBase.class, "layout", PatternLayout.class);
72            registry
73          .add(EvaluatorFilter.class, "evaluator", JaninoEventEvaluator.class);
74  
75      registry.add(AppenderBase.class, "encoder", PatternLayoutEncoder.class);
76      registry.add(UnsynchronizedAppenderBase.class, "encoder", PatternLayoutEncoder.class);
77    }
78  
79  }