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.ConfigurationAction;
17 import ch.qos.logback.classic.joran.action.ConsolePluginAction;
18 import ch.qos.logback.classic.joran.action.ContextNameAction;
19 import ch.qos.logback.classic.joran.action.InsertFromJNDIAction;
20 import ch.qos.logback.classic.joran.action.LevelAction;
21 import ch.qos.logback.classic.joran.action.LoggerAction;
22 import ch.qos.logback.classic.joran.action.LoggerContextListenerAction;
23 import ch.qos.logback.classic.joran.action.ReceiverAction;
24 import ch.qos.logback.classic.joran.action.RootLoggerAction;
25 import ch.qos.logback.classic.joran.sanity.IfNestedWithinSecondPhaseElementSC;
26 import ch.qos.logback.classic.model.processor.ConfigurationModelHandlerFull;
27 import ch.qos.logback.classic.model.processor.LogbackClassicDefaultNestedComponentRules;
28 import ch.qos.logback.classic.spi.ILoggingEvent;
29 import ch.qos.logback.core.joran.GenericXMLConfigurator;
30 import ch.qos.logback.core.joran.JoranConfiguratorBase;
31 import ch.qos.logback.core.joran.action.AppenderRefAction;
32 import ch.qos.logback.core.joran.action.IncludeAction;
33 import ch.qos.logback.core.joran.spi.DefaultNestedComponentRegistry;
34 import ch.qos.logback.core.joran.spi.ElementSelector;
35 import ch.qos.logback.core.joran.spi.RuleStore;
36 import ch.qos.logback.core.model.Model;
37 import ch.qos.logback.core.model.processor.DefaultProcessor;
38 import ch.qos.logback.core.model.processor.ModelInterpretationContext;
39
40
41
42
43
44
45 public class JoranConfigurator extends JoranConfiguratorBase<ILoggingEvent> {
46
47
48
49 @Override
50 public void addElementSelectorAndActionAssociations(RuleStore rs) {
51
52 super.addElementSelectorAndActionAssociations(rs);
53
54 rs.addRule(new ElementSelector("configuration"), () -> new ConfigurationAction());
55
56 rs.addRule(new ElementSelector("configuration/contextName"), () -> new ContextNameAction());
57 rs.addRule(new ElementSelector("configuration/contextListener"), () -> new LoggerContextListenerAction());
58 rs.addRule(new ElementSelector("configuration/insertFromJNDI"), () -> new InsertFromJNDIAction());
59
60 rs.addRule(new ElementSelector("configuration/logger"), () -> new LoggerAction());
61 rs.addRule(new ElementSelector("configuration/logger/level"), () -> new LevelAction());
62
63 rs.addRule(new ElementSelector("configuration/root"), () -> new RootLoggerAction());
64 rs.addRule(new ElementSelector("configuration/root/level"), () -> new LevelAction());
65 rs.addRule(new ElementSelector("configuration/logger/appender-ref"), () -> new AppenderRefAction());
66 rs.addRule(new ElementSelector("configuration/root/appender-ref"), () -> new AppenderRefAction());
67
68 rs.addRule(new ElementSelector("configuration/include"), () -> new IncludeAction());
69
70 rs.addRule(new ElementSelector("configuration/consolePlugin"), () -> new ConsolePluginAction());
71
72 rs.addRule(new ElementSelector("configuration/receiver"), () -> new ReceiverAction());
73
74 }
75
76
77 @Override
78 protected void sanityCheck(Model topModel) {
79 super.sanityCheck(topModel);
80 performCheck(new IfNestedWithinSecondPhaseElementSC(), topModel);
81 }
82
83 @Override
84 protected void addDefaultNestedComponentRegistryRules(DefaultNestedComponentRegistry registry) {
85 LogbackClassicDefaultNestedComponentRules.addDefaultNestedComponentRegistryRules(registry);
86 }
87
88 private JoranConfigurator makeAnotherInstance() {
89 JoranConfigurator jc = new JoranConfigurator();
90 jc.setContext(context);
91 return jc;
92 }
93
94 public void buildModelInterpretationContext() {
95 super.buildModelInterpretationContext();
96 this.modelInterpretationContext.setConfiguratorSupplier( () -> this.makeAnotherInstance() );
97 }
98
99 @Override
100 protected void addModelHandlerAssociations(DefaultProcessor defaultProcessor) {
101 ModelClassToModelHandlerLinker m = new ModelClassToModelHandlerLinker(context);
102 m.setConfigurationModelHandlerFactoryMethod(ConfigurationModelHandlerFull::makeInstance2);
103 m.link(defaultProcessor);
104 }
105
106
107
108
109
110
111 private void sealModelFilters(DefaultProcessor defaultProcessor) {
112 defaultProcessor.getPhaseOneFilter().denyAll();
113 defaultProcessor.getPhaseTwoFilter().allowAll();
114 }
115
116 }