Author: rgoers
Date: Sat May 10 04:02:33 2014
New Revision: 1593662
URL: http://svn.apache.org/r1593662
Log:
Detect web module using a property
Added:
logging/log4j/log4j2/trunk/log4j-web/src/main/resources/log4j2.component.properties
logging/log4j/log4j2/trunk/log4j-web/src/test/java/org/apache/logging/log4j/web/WebPropertyTest.java
Modified:
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
Modified:
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java?rev=1593662&r1=1593661&r2=1593662&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
(original)
+++
logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
Sat May 10 04:02:33 2014
@@ -18,6 +18,8 @@ package org.apache.logging.log4j.util;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
import java.util.Properties;
import org.apache.logging.log4j.Logger;
@@ -70,8 +72,30 @@ public final class PropertiesUtil {
public PropertiesUtil(final String propsLocn) {
final ClassLoader loader = ProviderUtil.findClassLoader();
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
- final InputStream in = loader.getResourceAsStream(propsLocn);
- this.props = loadClose(in, propsLocn);
+ Properties properties = new Properties();
+ try {
+ Enumeration<URL> enumeration = loader.getResources(propsLocn);
+ while (enumeration.hasMoreElements()) {
+ final URL url = enumeration.nextElement();
+ final InputStream in = url.openStream();
+ try {
+ properties.load(in);
+ } catch (IOException ioe) {
+ LOGGER.error("Unable to read {}", url.toString());
+ } finally {
+ try {
+ in.close();
+ } catch (IOException ioe) {
+ LOGGER.error("Unable to close {}", url.toString(),
ioe);
+ }
+ }
+
+ }
+
+ } catch (IOException ioe) {
+ LOGGER.error("Unable to access {}", propsLocn, ioe);
+ }
+ this.props = properties;
}
public static PropertiesUtil getProperties() {
Modified:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java?rev=1593662&r1=1593661&r2=1593662&view=diff
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
(original)
+++
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
Sat May 10 04:02:33 2014
@@ -45,6 +45,7 @@ import org.apache.logging.log4j.core.jmx
import org.apache.logging.log4j.message.MessageFactory;
import org.apache.logging.log4j.spi.AbstractLoggerProvider;
import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
/**
* The LoggerContext is the anchor for the logging system. It maintains a list
@@ -55,11 +56,7 @@ import org.apache.logging.log4j.status.S
*/
public class LoggerContext implements
org.apache.logging.log4j.spi.LoggerContext, ConfigurationListener, LifeCycle {
- static {
- USING_LOG4J_WEB =
Loader.isClassAvailable("org.apache.logging.log4j.web.Log4jWebSupport");
- }
-
- private static final boolean USING_LOG4J_WEB;
+ private static final boolean USING_LOG4J_WEB =
PropertiesUtil.getProperties().getBooleanProperty("log4j-web", false);
public static final String PROPERTY_CONFIG = "config";
private static final org.apache.logging.log4j.Logger LOGGER =
StatusLogger.getLogger();
Added:
logging/log4j/log4j2/trunk/log4j-web/src/main/resources/log4j2.component.properties
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-web/src/main/resources/log4j2.component.properties?rev=1593662&view=auto
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-web/src/main/resources/log4j2.component.properties
(added)
+++
logging/log4j/log4j2/trunk/log4j-web/src/main/resources/log4j2.component.properties
Sat May 10 04:02:33 2014
@@ -0,0 +1 @@
+log4j-web=true
\ No newline at end of file
Added:
logging/log4j/log4j2/trunk/log4j-web/src/test/java/org/apache/logging/log4j/web/WebPropertyTest.java
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-web/src/test/java/org/apache/logging/log4j/web/WebPropertyTest.java?rev=1593662&view=auto
==============================================================================
---
logging/log4j/log4j2/trunk/log4j-web/src/test/java/org/apache/logging/log4j/web/WebPropertyTest.java
(added)
+++
logging/log4j/log4j2/trunk/log4j-web/src/test/java/org/apache/logging/log4j/web/WebPropertyTest.java
Sat May 10 04:02:33 2014
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.web;
+
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ *
+ */
+public class WebPropertyTest {
+
+ @Test
+ public void testWebProperty() {
+
assertTrue(PropertiesUtil.getProperties().getBooleanProperty("log4j-web",
false));
+ }
+}