1 /**
2  * Logback: the reliable, generic, fast and flexible logging framework.
3  * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4  *
5  * This program and the accompanying materials are dual-licensed under
6  * either the terms of the Eclipse Public License v1.0 as published by
7  * the Eclipse Foundation
8  *
9  *   or (per the licensee's choosing)
10  *
11  * under the terms of the GNU Lesser General Public License version 2.1
12  * as published by the Free Software Foundation.
13  */

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 /**
25  * Action to handle the <level> element nested within <logger> element. 
26  * 
27  * <p>This action is <b>deprecated</b>. Use the level attribute within the logger
28  * element.
29  * 
30  * @author Ceki Gulcu
31  */

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         // addInfo("Encapsulating logger name is [" + loggerName
51         // + "], level value is  [" + levelStr + "].");
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