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.access.joran.action;
15  
16  import org.xml.sax.Attributes;
17  
18  import ch.qos.logback.core.joran.action.Action;
19  import ch.qos.logback.core.joran.spi.InterpretationContext;
20  import ch.qos.logback.core.status.OnConsoleStatusListener;
21  import ch.qos.logback.core.util.OptionHelper;
22  import ch.qos.logback.core.util.StatusListenerConfigHelper;
23  
24  public class ConfigurationAction extends Action {
25      static final String INTERNAL_DEBUG_ATTR = "debug";
26      static final String DEBUG_SYSTEM_PROPERTY_KEY = "logback-access.debug";
27  
28      @Override
29      public void begin(InterpretationContext ec, String name, Attributes attributes) {
30  
31          // See LBCLASSIC-225 (the system property is looked up first. Thus, it overrides
32          // the equivalent property in the config file. This reversal of scope priority is justified
33          // by the use case: the admin trying to chase rogue config file
34          String debugAttrib = System.getProperty(DEBUG_SYSTEM_PROPERTY_KEY);
35          if (debugAttrib == null) {
36              debugAttrib = attributes.getValue(INTERNAL_DEBUG_ATTR);
37          }
38  
39          if (OptionHelper.isEmpty(debugAttrib) || debugAttrib.equals("false") || debugAttrib.equals("null")) {
40              addInfo(INTERNAL_DEBUG_ATTR + " attribute not set");
41          } else {
42              StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener());
43          }
44  
45          // the context is appender attachable, so it is pushed on top of the stack
46          ec.pushObject(getContext());
47      }
48  
49      @Override
50      public void end(InterpretationContext ec, String name) {
51          addInfo("End of configuration.");
52          ec.popObject();
53      }
54  }