001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2022, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.access.common.joran; 015 016import ch.qos.logback.access.common.model.processor.LogbackAccessDefaultNestedComponentRegistryRules; 017import ch.qos.logback.access.common.spi.IAccessEvent; 018import ch.qos.logback.access.common.joran.action.ConfigurationAction; 019import ch.qos.logback.core.joran.JoranConfiguratorBase; 020import ch.qos.logback.core.joran.action.AppenderRefAction; 021import ch.qos.logback.core.joran.action.IncludeAction; 022import ch.qos.logback.core.joran.spi.DefaultNestedComponentRegistry; 023import ch.qos.logback.core.joran.spi.ElementSelector; 024import ch.qos.logback.core.joran.spi.RuleStore; 025import ch.qos.logback.core.model.processor.DefaultProcessor; 026 027/** 028 * This JoranConfiguratorclass adds rules specific to logback-access. 029 * 030 * @author Ceki Gülcü 031 */ 032public class JoranConfigurator extends JoranConfiguratorBase<IAccessEvent> { 033 034 @Override 035 public void addElementSelectorAndActionAssociations(RuleStore rs) { 036 super.addElementSelectorAndActionAssociations(rs); 037 038 rs.addRule(new ElementSelector("configuration"), () -> new ConfigurationAction()); 039 rs.addRule(new ElementSelector("configuration/appender-ref"), () -> new AppenderRefAction()); 040 rs.addRule(new ElementSelector("configuration/include"), () -> new IncludeAction()); 041 } 042 043 @Override 044 protected void addModelHandlerAssociations(DefaultProcessor defaultProcessor) { 045 046 ModelClassToModelHandlerLinker mham = new ModelClassToModelHandlerLinker(context); 047 mham.link(defaultProcessor); 048 049 } 050 051 052 @Override 053 protected void addDefaultNestedComponentRegistryRules(DefaultNestedComponentRegistry registry) { 054 LogbackAccessDefaultNestedComponentRegistryRules.addDefaultNestedComponentRegistryRules(registry); 055 } 056 057 private JoranConfigurator makeAnotherInstance() { 058 JoranConfigurator jc = new JoranConfigurator(); 059 jc.setContext(context); 060 return jc; 061 } 062 063 public void buildModelInterpretationContext() { 064 super.buildModelInterpretationContext(); 065 this.modelInterpretationContext.setConfiguratorSupplier( () -> this.makeAnotherInstance() ); 066 } 067}