1
2
3
4
5
6
7
8
9
10 package ch.qos.logback.classic.joran.action;
11
12 import org.xml.sax.Attributes;
13
14 import ch.qos.logback.classic.Level;
15 import ch.qos.logback.classic.Logger;
16 import ch.qos.logback.classic.LoggerContext;
17 import ch.qos.logback.core.joran.action.Action;
18 import ch.qos.logback.core.joran.action.ActionConst;
19 import ch.qos.logback.core.joran.spi.InterpretationContext;
20 import ch.qos.logback.core.util.OptionHelper;
21
22 public class RootLoggerAction extends Action {
23
24 Logger root;
25 boolean inError = false;
26
27 public void begin(InterpretationContext ec, String name, Attributes attributes) {
28 inError = false;
29
30 LoggerContext loggerContext = (LoggerContext) this.context;
31 root = loggerContext.getLogger(LoggerContext.ROOT_NAME);
32
33 String levelStr = ec.subst(attributes.getValue(ActionConst.LEVEL_ATTRIBUTE));
34 if (!OptionHelper.isEmpty(levelStr)) {
35 Level level = Level.toLevel(levelStr);
36 addInfo("Setting level of ROOT logger to " + level);
37 root.setLevel(level);
38 }
39
40 ec.pushObject(root);
41 }
42
43 public void end(InterpretationContext ec, String name) {
44 if (inError) {
45 return;
46 }
47 Object o = ec.peekObject();
48 if (o != root) {
49 addWarn("The object on the top the of the stack is not the root logger");
50 addWarn("It is: " + o);
51 } else {
52 ec.popObject();
53 }
54 }
55
56 public void finish(InterpretationContext ec) {
57 }
58 }