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