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