View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2022, 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.joran.action.ConfigurationAction;
17  import ch.qos.logback.access.model.ConfigurationModel;
18  import ch.qos.logback.access.model.processor.ConfigurationModelHandler;
19  import ch.qos.logback.access.model.processor.LogbackAccessDefaultNestedComponentRegistryRules;
20  import ch.qos.logback.access.spi.IAccessEvent;
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.spi.DefaultNestedComponentRegistry;
25  import ch.qos.logback.core.joran.spi.ElementSelector;
26  import ch.qos.logback.core.joran.spi.RuleStore;
27  import ch.qos.logback.core.model.AppenderModel;
28  import ch.qos.logback.core.model.AppenderRefModel;
29  import ch.qos.logback.core.model.processor.AppenderModelHandler;
30  import ch.qos.logback.core.model.processor.AppenderRefDependencyAnalyser;
31  import ch.qos.logback.core.model.processor.AppenderRefModelHandler;
32  import ch.qos.logback.core.model.processor.DefaultProcessor;
33  import ch.qos.logback.core.model.processor.RefContainerDependencyAnalyser;
34  
35  /**
36   * This JoranConfiguratorclass adds rules specific to logback-access.
37   *
38   * @author Ceki Gülcü
39   */
40  public class JoranConfigurator extends JoranConfiguratorBase<IAccessEvent> {
41  
42      @Override
43      public void addElementSelectorAndActionAssociations(RuleStore rs) {
44          super.addElementSelectorAndActionAssociations(rs);
45  
46          rs.addRule(new ElementSelector("configuration"), () -> new ConfigurationAction());
47          rs.addRule(new ElementSelector("configuration/appender-ref"), () -> new AppenderRefAction());
48          rs.addRule(new ElementSelector("configuration/include"), () -> new IncludeAction());
49      }
50  
51      @Override
52      protected void addModelHandlerAssociations(DefaultProcessor defaultProcessor) {
53          super.addModelHandlerAssociations(defaultProcessor);
54          defaultProcessor.addHandler(ConfigurationModel.class, ConfigurationModelHandler::makeInstance);
55          defaultProcessor.addHandler(AppenderModel.class, AppenderModelHandler::makeInstance); 
56          defaultProcessor.addHandler(AppenderRefModel.class, AppenderRefModelHandler::makeInstance);
57  
58          defaultProcessor.addAnalyser(AppenderModel.class, () -> 
59                  new RefContainerDependencyAnalyser(context, AppenderModel.class));
60          defaultProcessor.addAnalyser(AppenderRefModel.class, () -> new AppenderRefDependencyAnalyser(context));
61  
62          sealModelFilters(defaultProcessor);
63      }
64  
65      // The final filters in the two filter chain are rather crucial.
66      // They ensure that only Models attached to the firstPhaseFilter will
67      // be handled in the first phase and all models not previously handled
68      // in the second phase will be handled in a catch-all fallback case.
69      private void sealModelFilters(DefaultProcessor defaultProcessor) {
70          defaultProcessor.getPhaseOneFilter().denyAll();
71          defaultProcessor.getPhaseTwoFilter().allowAll();
72      }
73  
74      @Override
75      protected void addDefaultNestedComponentRegistryRules(DefaultNestedComponentRegistry registry) {
76          LogbackAccessDefaultNestedComponentRegistryRules.addDefaultNestedComponentRegistryRules(registry);    
77      }
78  
79  }