View Javadoc
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.model.LevelModel;
19  import ch.qos.logback.core.joran.action.Action;
20  import ch.qos.logback.core.joran.JoranConstants;
21  import ch.qos.logback.core.joran.action.BaseModelAction;
22  import ch.qos.logback.core.joran.action.PreconditionValidator;
23  import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
24  import ch.qos.logback.core.model.Model;
25  
26  /**
27   * Action to handle the <level> element nested within <logger> element.
28   * 
29   * <p>
30   * This action is <b>deprecated</b>. Use the level attribute within the logger
31   * element.
32   * 
33   * @author Ceki Gulcu
34   */
35  public class LevelAction extends BaseModelAction {
36  
37      @Override
38      protected boolean validPreconditions(SaxEventInterpretationContext interpcont, String name, Attributes attributes) {
39          PreconditionValidator pv = new PreconditionValidator(this, interpcont, name, attributes);
40          pv.validateValueAttribute();
41          addWarn("<level> element is deprecated. Near [" + name + "] on line " + Action.getLineNumber(interpcont));
42          addWarn("Please use \"level\" attribute within <logger> or <root> elements instead.");
43          return pv.isValid();
44      }
45  
46      @Override
47      protected Model buildCurrentModel(SaxEventInterpretationContext interpretationContext, String name,
48              Attributes attributes) {
49          LevelModel lm = new LevelModel();
50          String value = attributes.getValue(JoranConstants.VALUE_ATTR);
51          lm.setValue(value);
52  
53          return lm;
54      }
55  
56  }