1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.joran.action;
15
16 import ch.qos.logback.core.joran.action.PreconditionValidator;
17 import org.xml.sax.Attributes;
18
19 import ch.qos.logback.classic.Logger;
20 import ch.qos.logback.classic.model.RootLoggerModel;
21 import ch.qos.logback.core.joran.JoranConstants;
22 import ch.qos.logback.core.joran.action.BaseModelAction;
23 import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
24 import ch.qos.logback.core.model.Model;
25 import static ch.qos.logback.core.joran.JoranConstants.NULL;
26 import static ch.qos.logback.core.joran.JoranConstants.INHERITED;
27 import static ch.qos.logback.core.spi.ErrorCodes.ROOT_LEVEL_CANNOT_BE_SET_TO_NULL;
28
29 public class RootLoggerAction extends BaseModelAction {
30
31 Logger root;
32 boolean inError = false;
33
34 @Override
35 protected boolean validPreconditions(SaxEventInterpretationContext interpcont, String name, Attributes attributes) {
36 PreconditionValidator pv;
37 String levelStr = attributes.getValue(JoranConstants.LEVEL_ATTRIBUTE);
38 if(NULL.equalsIgnoreCase(levelStr) || INHERITED.equalsIgnoreCase(levelStr)) {
39 addError(ROOT_LEVEL_CANNOT_BE_SET_TO_NULL);
40 return false;
41 }
42 return true;
43 }
44 @Override
45 protected Model buildCurrentModel(SaxEventInterpretationContext interpretationContext, String name,
46 Attributes attributes) {
47 RootLoggerModel rootLoggerModel = new RootLoggerModel();
48 String levelStr = attributes.getValue(JoranConstants.LEVEL_ATTRIBUTE);
49 rootLoggerModel.setLevel(levelStr);
50
51 return rootLoggerModel;
52 }
53
54 }