View Javadoc

1   /**
2    * Logback: the generic, reliable, fast and flexible logging framework.
3    * 
4    * Copyright (C) 2000-2008, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
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   * Action to handle the <level> element nested within <logger> element. 
22   * 
23   * <p>This action is <b>deprecated</b>. Use the level attribute within the logger
24   * element.
25   * 
26   * @author Ceki Gulcu
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      //addInfo("Encapsulating logger name is [" + loggerName
47      //    + "], level value is  [" + levelStr + "].");
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  }