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.classic.joran;
15  
16  import ch.qos.logback.classic.joran.action.*;
17  import ch.qos.logback.classic.sift.SiftAction;
18  import ch.qos.logback.classic.spi.PlatformInfo;
19  import ch.qos.logback.classic.util.DefaultNestedComponentRules;
20  import ch.qos.logback.core.joran.JoranConfiguratorBase;
21  import ch.qos.logback.core.joran.action.AppenderRefAction;
22  import ch.qos.logback.core.joran.action.IncludeAction;
23  import ch.qos.logback.core.joran.action.NOPAction;
24  import ch.qos.logback.core.joran.conditional.ElseAction;
25  import ch.qos.logback.core.joran.conditional.IfAction;
26  import ch.qos.logback.core.joran.conditional.ThenAction;
27  import ch.qos.logback.core.joran.spi.DefaultNestedComponentRegistry;
28  import ch.qos.logback.core.joran.spi.Pattern;
29  import ch.qos.logback.core.joran.spi.RuleStore;
30  
31  /**
32   * This JoranConfiguratorclass adds rules specific to logback-classic.
33   *
34   * @author Ceki Gülcü
35   */
36  public class JoranConfigurator extends JoranConfiguratorBase {
37  
38    public JoranConfigurator() {
39    }
40  
41    @Override
42    public void addInstanceRules(RuleStore rs) {
43      // parent rules already added
44      super.addInstanceRules(rs);
45  
46      rs.addRule(new Pattern("configuration"), new ConfigurationAction());
47  
48      rs.addRule(new Pattern("configuration/contextName"),
49          new ContextNameAction());
50        rs.addRule(new Pattern("configuration/contextListener"),
51          new LoggerContextListenerAction());
52      rs.addRule(new Pattern("configuration/insertFromJNDI"),
53          new InsertFromJNDIAction());
54      rs.addRule(new Pattern("configuration/evaluator"), new EvaluatorAction());
55  
56      rs.addRule(new Pattern("configuration/appender/sift"), new SiftAction());
57      rs.addRule(new Pattern("configuration/appender/sift/*"), new NOPAction());
58  
59      rs.addRule(new Pattern("configuration/logger"), new LoggerAction());
60      rs.addRule(new Pattern("configuration/logger/level"), new LevelAction());
61  
62      rs.addRule(new Pattern("configuration/root"), new RootLoggerAction());
63      rs.addRule(new Pattern("configuration/root/level"), new LevelAction());
64      rs.addRule(new Pattern("configuration/logger/appender-ref"),
65          new AppenderRefAction());
66      rs.addRule(new Pattern("configuration/root/appender-ref"),
67          new AppenderRefAction());
68      
69      // add if-then-else support
70      rs.addRule(new Pattern("*/if"), new IfAction());
71      rs.addRule(new Pattern("*/if/then"), new ThenAction());
72      rs.addRule(new Pattern("*/if/then/*"), new NOPAction());
73      rs.addRule(new Pattern("*/if/else"), new ElseAction());
74      rs.addRule(new Pattern("*/if/else/*"), new NOPAction());   
75      
76      // add jmxConfigurator only if we have JMX available.
77      // If running under JDK 1.4 (retrotranslateed logback) then we
78      // might not have JMX.
79      if (PlatformInfo.hasJMXObjectName()) {
80        rs.addRule(new Pattern("configuration/jmxConfigurator"),
81            new JMXConfiguratorAction());
82      }
83      rs.addRule(new Pattern("configuration/include"), new IncludeAction());
84  
85      rs.addRule(new Pattern("configuration/consolePlugin"),
86          new ConsolePluginAction());
87    }
88  
89    @Override
90    protected void addDefaultNestedComponentRegistryRules(
91        DefaultNestedComponentRegistry registry) {
92      DefaultNestedComponentRules.addDefaultNestedComponentRegistryRules(registry);
93    }
94  
95  }