1
14 package ch.qos.logback.classic.joran.action;
15
16 import org.xml.sax.Attributes;
17
18 import ch.qos.logback.classic.Level;
19 import ch.qos.logback.classic.Logger;
20 import ch.qos.logback.core.joran.action.Action;
21 import ch.qos.logback.core.joran.action.ActionConst;
22 import ch.qos.logback.core.joran.spi.InterpretationContext;
23
24
32 public class LevelAction extends Action {
33
34 boolean inError = false;
35
36 public void begin(InterpretationContext ec, String name, Attributes attributes) {
37 Object o = ec.peekObject();
38
39 if (!(o instanceof Logger)) {
40 inError = true;
41 addError("For element <level>, could not find a logger at the top of execution stack.");
42 return;
43 }
44
45 Logger l = (Logger) o;
46
47 String loggerName = l.getName();
48
49 String levelStr = ec.subst(attributes.getValue(ActionConst.VALUE_ATTR));
50
51
52
53 if (ActionConst.INHERITED.equalsIgnoreCase(levelStr) || ActionConst.NULL.equalsIgnoreCase(levelStr)) {
54 l.setLevel(null);
55 } else {
56 l.setLevel(Level.toLevel(levelStr, Level.DEBUG));
57 }
58
59 addInfo(loggerName + " level set to " + l.getLevel());
60 }
61
62 public void finish(InterpretationContext ec) {
63 }
64
65 public void end(InterpretationContext ec, String e) {
66 }
67 }
68