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.LoggerModel;
19  import ch.qos.logback.core.joran.JoranConstants;
20  import ch.qos.logback.core.joran.action.BaseModelAction;
21  import ch.qos.logback.core.joran.action.PreconditionValidator;
22  import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
23  import ch.qos.logback.core.model.Model;
24  
25  /**
26   * Action which handles <logger> elements in configuration files.
27   * 
28   * @author Ceki G&uuml;lc&uuml;
29   */
30  public class LoggerAction extends BaseModelAction {
31  
32      @Override
33      protected boolean validPreconditions(SaxEventInterpretationContext ic, String name, Attributes attributes) {
34          PreconditionValidator validator = new PreconditionValidator(this, ic, name, attributes);
35          validator.validateNameAttribute();
36          return validator.isValid();
37      }
38  
39      @Override
40      protected Model buildCurrentModel(SaxEventInterpretationContext interpretationContext, String name,
41              Attributes attributes) {
42  
43          LoggerModel loggerModel = new LoggerModel();
44  
45          String nameStr = attributes.getValue(NAME_ATTRIBUTE);
46          loggerModel.setName(nameStr);
47  
48          String levelStr = attributes.getValue(JoranConstants.LEVEL_ATTRIBUTE);
49          loggerModel.setLevel(levelStr);
50  
51          String additivityStr = attributes.getValue(JoranConstants.ADDITIVITY_ATTRIBUTE);
52          loggerModel.setAdditivity(additivityStr);
53  
54          return loggerModel;
55      }
56  }