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 ch.qos.logback.core.joran.action.PreconditionValidator;
17  import org.xml.sax.Attributes;
18  
19  import ch.qos.logback.classic.Logger;
20  import ch.qos.logback.classic.model.RootLoggerModel;
21  import ch.qos.logback.core.joran.JoranConstants;
22  import ch.qos.logback.core.joran.action.BaseModelAction;
23  import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
24  import ch.qos.logback.core.model.Model;
25  import static ch.qos.logback.core.joran.JoranConstants.NULL;
26  import static ch.qos.logback.core.joran.JoranConstants.INHERITED;
27  import static ch.qos.logback.core.spi.ErrorCodes.ROOT_LEVEL_CANNOT_BE_SET_TO_NULL;
28  
29  public class RootLoggerAction extends BaseModelAction {
30  
31      Logger root;
32      boolean inError = false;
33  
34      @Override
35      protected boolean validPreconditions(SaxEventInterpretationContext interpcont, String name, Attributes attributes) {
36          PreconditionValidator pv;
37          String levelStr = attributes.getValue(JoranConstants.LEVEL_ATTRIBUTE);
38          if(NULL.equalsIgnoreCase(levelStr) || INHERITED.equalsIgnoreCase(levelStr)) {
39              addError(ROOT_LEVEL_CANNOT_BE_SET_TO_NULL);
40              return false;
41          }
42          return true;
43      }
44      @Override
45      protected Model buildCurrentModel(SaxEventInterpretationContext interpretationContext, String name,
46              Attributes attributes) {
47          RootLoggerModel rootLoggerModel = new RootLoggerModel();
48          String levelStr = attributes.getValue(JoranConstants.LEVEL_ATTRIBUTE);
49          rootLoggerModel.setLevel(levelStr);
50  
51          return rootLoggerModel;
52      }
53  
54  }