You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2013/07/06 08:55:49 UTC
svn commit: r1500212 - in /logging/log4j/log4j2/trunk:
core/src/main/java/org/apache/logging/log4j/core/config/
core/src/main/java/org/apache/logging/log4j/core/helpers/
core/src/test/java/org/apache/logging/log4j/core/config/
core/src/test/resources/ ...
Author: rgoers
Date: Sat Jul 6 06:55:49 2013
New Revision: 1500212
URL: http://svn.apache.org/r1500212
Log:
LOG4J2-282 - Allow the default status level to be specified as a system property.
Added:
logging/log4j/log4j2/trunk/core/src/test/resources/log4j-props1.xml
- copied, changed from r1499916, logging/log4j/log4j2/trunk/core/src/test/resources/log4j-props.xml
Modified:
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Constants.java
logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationPropsTest.java
logging/log4j/log4j2/trunk/src/changes/changes.xml
logging/log4j/log4j2/trunk/src/site/xdoc/manual/configuration.xml.vm
Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java?rev=1500212&r1=1500211&r2=1500212&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java Sat Jul 6 06:55:49 2013
@@ -32,6 +32,7 @@ import org.apache.logging.log4j.core.con
import org.apache.logging.log4j.core.config.plugins.PluginType;
import org.apache.logging.log4j.core.config.plugins.PluginValue;
import org.apache.logging.log4j.core.filter.AbstractFilterable;
+import org.apache.logging.log4j.core.helpers.Constants;
import org.apache.logging.log4j.core.helpers.NameUtil;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.apache.logging.log4j.core.lookup.Interpolator;
@@ -152,6 +153,16 @@ public class BaseConfiguration extends A
protected void setup() {
}
+ protected Level getDefaultStatus() {
+ String statusLevel = PropertiesUtil.getProperties().getStringProperty(Constants.LOG4J_DEFAULT_STATUS_LEVEL,
+ Level.ERROR.name());
+ try {
+ return Level.toLevel(statusLevel);
+ } catch (Exception ex) {
+ return Level.ERROR;
+ }
+ }
+
@Override
public Object getComponent(final String name) {
return componentMap.get(name);
Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java?rev=1500212&r1=1500211&r2=1500212&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java Sat Jul 6 06:55:49 2013
@@ -60,7 +60,7 @@ public class JSONConfiguration extends B
private final List<Status> status = new ArrayList<Status>();
private Map<String, String> advertisedConfiguration;
-
+
private Object advertisement;
private JsonNode root;
@@ -85,7 +85,7 @@ public class JSONConfiguration extends B
root = i.next();
}
processAttributes(rootNode, root);
- Level status = Level.OFF;
+ Level status = getDefaultStatus();
boolean verbose = false;
PrintStream stream = System.out;
for (final Map.Entry<String, String> entry : rootNode.getAttributes().entrySet()) {
Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java?rev=1500212&r1=1500211&r2=1500212&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java Sat Jul 6 06:55:49 2013
@@ -43,15 +43,18 @@ import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
+import com.sun.org.apache.bcel.internal.classfile.ConstantString;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.plugins.PluginManager;
import org.apache.logging.log4j.core.config.plugins.PluginType;
import org.apache.logging.log4j.core.config.plugins.ResolverUtil;
+import org.apache.logging.log4j.core.helpers.Constants;
import org.apache.logging.log4j.core.helpers.FileUtils;
import org.apache.logging.log4j.core.net.Advertiser;
import org.apache.logging.log4j.status.StatusConsoleListener;
import org.apache.logging.log4j.status.StatusListener;
import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -103,16 +106,17 @@ public class XMLConfiguration extends Ba
final Document document = builder.parse(source);
rootElement = document.getDocumentElement();
final Map<String, String> attrs = processAttributes(rootNode, rootElement);
- Level status = Level.OFF;
+ Level status = getDefaultStatus();
boolean verbose = false;
PrintStream stream = System.out;
for (final Map.Entry<String, String> entry : attrs.entrySet()) {
if ("status".equalsIgnoreCase(entry.getKey())) {
- status = Level.toLevel(getSubst().replace(entry.getValue()), null);
- if (status == null) {
- status = Level.ERROR;
- messages.add("Invalid status specified: " + entry.getValue() + ". Defaulting to ERROR");
+ Level stat = Level.toLevel(getSubst().replace(entry.getValue()), null);
+ if (stat != null) {
+ status = stat;
+ } else {
+ messages.add("Invalid status specified: " + entry.getValue() + ". Defaulting to " + status);
}
} else if ("dest".equalsIgnoreCase(entry.getKey())) {
final String dest = entry.getValue();
Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Constants.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Constants.java?rev=1500212&r1=1500211&r2=1500212&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Constants.java (original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Constants.java Sat Jul 6 06:55:49 2013
@@ -23,12 +23,18 @@ import org.apache.logging.log4j.util.Pro
*/
public final class Constants {
+ /**
+ * Name of the system property to use to identify the LogEvent factory.
+ */
public static final String LOG4J_LOG_EVENT_FACTORY = "Log4jLogEventFactory";
+
/**
* Name of the system property to use to identify the ContextSelector Class.
*/
public static final String LOG4J_CONTEXT_SELECTOR = "Log4jContextSelector";
+ public static final String LOG4J_DEFAULT_STATUS_LEVEL = "Log4jDefaultStatusLevel";
+
/**
* JNDI context name string literal.
*/
Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationPropsTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationPropsTest.java?rev=1500212&r1=1500211&r2=1500212&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationPropsTest.java (original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationPropsTest.java Sat Jul 6 06:55:49 2013
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.co
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.helpers.Constants;
import org.apache.logging.log4j.status.StatusLogger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -31,6 +32,7 @@ import static org.junit.Assert.*;
public class XMLConfigurationPropsTest {
private static final String CONFIG = "log4j-props.xml";
+ private static final String CONFIG1 = "log4j-props1.xml";
private static final String LOGFILE = "target/test.log";
@BeforeClass
@@ -47,6 +49,7 @@ public class XMLConfigurationPropsTest {
@Test
public void testNoProps() {
+ System.out.println("No status");
System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
final LoggerContext ctx = (LoggerContext) LogManager.getContext();
ctx.reconfigure();
@@ -54,6 +57,22 @@ public class XMLConfigurationPropsTest {
assertTrue("Configuration is not an XMLConfiguration", config instanceof XMLConfiguration);
}
+
+ @Test
+ public void testDefaultStatus() {
+ System.out.println("Default status");
+ System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG1);
+ System.setProperty(Constants.LOG4J_DEFAULT_STATUS_LEVEL, "DEBUG");
+ try {
+ final LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ ctx.reconfigure();
+ final Configuration config = ctx.getConfiguration();
+ assertTrue("Configuration is not an XMLConfiguration", config instanceof XMLConfiguration);
+ } finally {
+ System.clearProperty(Constants.LOG4J_DEFAULT_STATUS_LEVEL);
+ }
+ }
+
@Test
public void testWithConfigProp() {
System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
Copied: logging/log4j/log4j2/trunk/core/src/test/resources/log4j-props1.xml (from r1499916, logging/log4j/log4j2/trunk/core/src/test/resources/log4j-props.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-props1.xml?p2=logging/log4j/log4j2/trunk/core/src/test/resources/log4j-props1.xml&p1=logging/log4j/log4j2/trunk/core/src/test/resources/log4j-props.xml&r1=1499916&r2=1500212&rev=1500212&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j-props.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j-props1.xml Sat Jul 6 06:55:49 2013
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<configuration status="${sys:log4j.level}" strict="false" name="DSI" packages="com.terradue.dsione">
+<configuration strict="false" name="DSI" packages="com.terradue.dsione">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5level] %msg%n" />
Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1500212&r1=1500211&r2=1500212&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sat Jul 6 06:55:49 2013
@@ -21,6 +21,9 @@
</properties>
<body>
<release version="2.0-beta8" date="2013-??-??" description="Bug fixes and enhancements">
+ <action issue="LOG4J2-282" dev="rgoers" type="update">
+ Allow the default status level to be specified as a system property.
+ </action>
<action issue="LOG4J2-278" dev="rgoers" type="fix">
Filter calls from Avro or Flume to be ignored by the FlumeAppender.
</action>
Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/configuration.xml.vm
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/configuration.xml.vm?rev=1500212&r1=1500211&r2=1500212&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/configuration.xml.vm (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/configuration.xml.vm Sat Jul 6 06:55:49 2013
@@ -880,7 +880,8 @@ public class Bar {
</p>
<p>
When configuring Log4j it is sometimes necessary to view the generated status events. This can be
- accomplished by adding the status attribute to the configuration element. The following
+ accomplished by adding the status attribute to the configuration element or a default value can be
+ provided by setting the "Log4jDefaultStatusLevel" system property. The following
configuration has the status attribute set to debug.
<pre class="prettyprint linenums"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>;