1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.joran;
15
16 import ch.qos.logback.classic.joran.action.*;
17 import ch.qos.logback.classic.joran.sanity.IfNestedWithinSecondPhaseElementSC;
18 import ch.qos.logback.classic.model.processor.ConfigurationModelHandlerFull;
19 import ch.qos.logback.classic.model.processor.LogbackClassicDefaultNestedComponentRules;
20 import ch.qos.logback.classic.spi.ILoggingEvent;
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.Model;
28 import ch.qos.logback.core.model.processor.DefaultProcessor;
29
30
31
32
33
34
35 public class JoranConfigurator extends JoranConfiguratorBase<ILoggingEvent> {
36
37
38
39 @Override
40 public void addElementSelectorAndActionAssociations(RuleStore rs) {
41
42 super.addElementSelectorAndActionAssociations(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
50 rs.addRule(new ElementSelector("configuration/logger"), () -> new LoggerAction());
51 rs.addRule(new ElementSelector("configuration/logger/level"), () -> new LevelAction());
52
53 rs.addRule(new ElementSelector("configuration/root"), () -> new RootLoggerAction());
54 rs.addRule(new ElementSelector("configuration/root/level"), () -> new LevelAction());
55 rs.addRule(new ElementSelector("configuration/logger/appender-ref"), () -> new AppenderRefAction());
56 rs.addRule(new ElementSelector("configuration/root/appender-ref"), () -> new AppenderRefAction());
57
58 rs.addRule(new ElementSelector("configuration/include"), () -> new IncludeAction());
59 rs.addRule(new ElementSelector("configuration/propertiesConfigurator"), () -> new PropertiesConfiguratorAction());
60
61 rs.addRule(new ElementSelector("configuration/consolePlugin"), () -> new ConsolePluginAction());
62
63 rs.addRule(new ElementSelector("configuration/receiver"), () -> new ReceiverAction());
64
65
66 }
67
68
69 @Override
70 protected void sanityCheck(Model topModel) {
71 super.sanityCheck(topModel);
72 performCheck(new IfNestedWithinSecondPhaseElementSC(), topModel);
73 }
74
75 @Override
76 protected void addDefaultNestedComponentRegistryRules(DefaultNestedComponentRegistry registry) {
77 LogbackClassicDefaultNestedComponentRules.addDefaultNestedComponentRegistryRules(registry);
78 }
79
80 private JoranConfigurator makeAnotherInstance() {
81 JoranConfigurator jc = new JoranConfigurator();
82 jc.setContext(context);
83 return jc;
84 }
85
86 public void buildModelInterpretationContext() {
87 super.buildModelInterpretationContext();
88 this.modelInterpretationContext.setConfiguratorSupplier( () -> this.makeAnotherInstance() );
89 }
90
91 @Override
92 protected void addModelHandlerAssociations(DefaultProcessor defaultProcessor) {
93 ModelClassToModelHandlerLinker m = new ModelClassToModelHandlerLinker(context);
94 m.setConfigurationModelHandlerFactoryMethod(ConfigurationModelHandlerFull::makeInstance2);
95 m.link(defaultProcessor);
96 }
97
98
99
100
101
102
103 private void sealModelFilters(DefaultProcessor defaultProcessor) {
104 defaultProcessor.getPhaseOneFilter().denyAll();
105 defaultProcessor.getPhaseTwoFilter().allowAll();
106 }
107
108 }