Return-Path:
X-Original-To: apmail-logging-commits-archive@minotaur.apache.org
Delivered-To: apmail-logging-commits-archive@minotaur.apache.org
Received: from mail.apache.org (hermes.apache.org [140.211.11.3])
by minotaur.apache.org (Postfix) with SMTP id D9D13A679
for ;
Thu, 24 Nov 2011 02:08:17 +0000 (UTC)
Received: (qmail 43340 invoked by uid 500); 24 Nov 2011 02:08:17 -0000
Delivered-To: apmail-logging-commits-archive@logging.apache.org
Received: (qmail 43316 invoked by uid 500); 24 Nov 2011 02:08:17 -0000
Mailing-List: contact commits-help@logging.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@logging.apache.org
Delivered-To: mailing list commits@logging.apache.org
Received: (qmail 43309 invoked by uid 99); 24 Nov 2011 02:08:17 -0000
Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230)
by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Nov 2011 02:08:17 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=5.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Nov 2011 02:08:11 +0000
Received: from eris.apache.org (localhost [127.0.0.1])
by eris.apache.org (Postfix) with ESMTP id 740732388993;
Thu, 24 Nov 2011 02:07:49 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r1205703 - in
/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers:
log4j12-api/src/test/java/org/apache/log4j/
log4j2-core/src/main/java/org/apache/logging/log4j/core/config/
log4j2-core/src/test/java/org/apache/logging/log4j/core/ src/s...
Date: Thu, 24 Nov 2011 02:07:48 -0000
To: commits@logging.apache.org
From: rgoers@apache.org
X-Mailer: svnmailer-1.0.8-patched
Message-Id: <20111124020749.740732388993@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: rgoers
Date: Thu Nov 24 02:07:47 2011
New Revision: 1205703
URL: http://svn.apache.org/viewvc?rev=1205703&view=rev
Log:
Started work on configuration documentation. Changed configuration loading to match documentation
Added:
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicLoggingTest.java
Modified:
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml
logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/configuration.xml
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java?rev=1205703&r1=1205702&r2=1205703&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java Thu Nov 24 02:07:47 2011
@@ -21,8 +21,7 @@ import org.apache.logging.log4j.core.con
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.LoggerConfig;
-import org.apache.logging.log4j.core.config.Order;
-import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.xml.sax.InputSource;
import java.net.URI;
@@ -31,6 +30,17 @@ import java.net.URI;
*/
public class BasicConfigurationFactory extends ConfigurationFactory {
+ @Override
+ public String[] getSupportedTypes() {
+ return new String[] {"*"};
+ }
+
+ @Override
+ public Configuration getConfiguration(InputSource source) {
+ return new BasicConfiguration();
+ }
+
+ @Override
public Configuration getConfiguration(String name, URI configLocation) {
return new BasicConfiguration();
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java?rev=1205703&r1=1205702&r2=1205703&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java Thu Nov 24 02:07:47 2011
@@ -3,9 +3,19 @@ package org.apache.logging.log4j.core.co
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.plugins.PluginManager;
import org.apache.logging.log4j.core.config.plugins.PluginType;
+import org.apache.logging.log4j.core.helpers.FileUtils;
+import org.apache.logging.log4j.core.helpers.Loader;
import org.apache.logging.log4j.status.StatusLogger;
+import org.xml.sax.InputSource;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -31,9 +41,19 @@ public abstract class ConfigurationFacto
public static final String CONFIGURATION_FACTORY_PROPERTY = "log4j.configurationFactory";
+ public static final String CONFIGURATION_FILE_PROPERTY = "log4j.configurationFile";
+
private static List factories = new ArrayList();
- private static Logger logger = StatusLogger.getLogger();
+ protected static Logger logger = StatusLogger.getLogger();
+
+ protected File configFile = null;
+
+ protected static final String TEST_PREFIX = "log4j2-test";
+
+ protected static final String DEFAULT_PREFIX = "log4j2";
+
+ private static ConfigurationFactory configFactory = new Factory();
public static ConfigurationFactory getInstance() {
String factoryClass = System.getProperty(CONFIGURATION_FACTORY_PROPERTY);
@@ -59,7 +79,7 @@ public abstract class ConfigurationFacto
for (WeightedFactory wf : ordered) {
addFactory(wf.factoryClass);
}
- return new Factory();
+ return configFactory;
}
private static void addFactory(String factoryClass) {
@@ -82,14 +102,92 @@ public abstract class ConfigurationFacto
}
public static void setConfigurationFactory(ConfigurationFactory factory) {
- factories.add(0, factory);
+ configFactory = factory;
+ }
+
+ public static void resetConfigurationFactory() {
+ configFactory = new Factory();
}
public static void removeConfigurationFactory(ConfigurationFactory factory) {
factories.remove(factory);
}
- public abstract Configuration getConfiguration(String name, URI configLocation);
+ protected abstract String[] getSupportedTypes();
+
+ protected boolean isActive() {
+ return true;
+ }
+
+ public abstract Configuration getConfiguration(InputSource source);
+
+ public Configuration getConfiguration(String name, URI configLocation) {
+ if (!isActive()) {
+ return null;
+ }
+ if (configLocation != null) {
+ InputSource source = getInputFromURI(configLocation);
+ if (source != null) {
+ return getConfiguration(source);
+ }
+ }
+ return null;
+ }
+
+ protected InputSource getInputFromURI(URI configLocation) {
+ configFile = FileUtils.fileFromURI(configLocation);
+ if (configFile != null && configFile.exists() && configFile.canRead()) {
+ try {
+ InputSource source = new InputSource(new FileInputStream(configFile));
+ source.setSystemId(configLocation.getPath());
+ return source;
+ } catch (FileNotFoundException ex) {
+ logger.error("Cannot locate file " + configLocation.getPath(), ex);
+ }
+ }
+ try {
+ InputSource source = new InputSource(configLocation.toURL().openStream());
+ source.setSystemId(configLocation.getPath());
+ return source;
+ } catch (MalformedURLException ex) {
+ logger.error("Invalid URL " + configLocation.toString(), ex);
+ } catch (IOException ex) {
+ logger.error("Unable to access " + configLocation.toString(), ex);
+ }
+ return null;
+ }
+
+ protected InputSource getInputFromString(ClassLoader loader, String configFile) {
+ InputSource source;
+ try {
+ URL url = new URL(configFile);
+ source = new InputSource(url.openStream());
+ source.setSystemId(configFile);
+ return source;
+ } catch (Exception ex) {
+ source = getInputFromResource(configFile, loader);
+ if (source == null) {
+ try {
+ InputStream is = new FileInputStream(configFile);
+ source = new InputSource(is);
+ source.setSystemId(configFile);
+ } catch (FileNotFoundException fnfe) {
+ // Ignore the exception
+ }
+ }
+ }
+ return source;
+ }
+
+ protected InputSource getInputFromResource(String resource, ClassLoader loader) {
+ InputStream is = Loader.getResourceAsStream(resource, loader);
+ if (is == null) {
+ return null;
+ }
+ InputSource source = new InputSource(is);
+ source.setSystemId(resource);
+ return source;
+ }
private static class WeightedFactory implements Comparable {
private int weight;
@@ -116,13 +214,81 @@ public abstract class ConfigurationFacto
public Configuration getConfiguration(String name, URI configLocation) {
+ if (configLocation == null) {
+ String config = System.getProperty(CONFIGURATION_FILE_PROPERTY);
+ if (config != null) {
+ ClassLoader loader = this.getClass().getClassLoader();
+ InputSource source = getInputFromString(loader, config);
+ if (source != null) {
+ for (ConfigurationFactory factory : factories) {
+ String[] types = factory.getSupportedTypes();
+ if (types != null) {
+ for (String type : types) {
+ if (type.equals("*") || config.endsWith(type)) {
+ Configuration c = factory.getConfiguration(source);
+ if (c != null) {
+ return c;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ for (ConfigurationFactory factory : factories) {
+ Configuration config = factory.getConfiguration(name, configLocation);
+ if (config != null) {
+ return config;
+ }
+ }
+ }
+
+ Configuration config = getConfiguration(true, name);
+ if (config == null) {
+ config = getConfiguration(true, null);
+ if (config == null) {
+ config = getConfiguration(false, name);
+ if (config == null) {
+ config = getConfiguration(false, null);
+ }
+ }
+ }
+ return config != null ? config : new DefaultConfiguration();
+ }
+
+ private Configuration getConfiguration(boolean isTest, String name) {
+ boolean named = (name != null && name.length() > 0);
+ ClassLoader loader = this.getClass().getClassLoader();
for (ConfigurationFactory factory : factories) {
- Configuration c = factory.getConfiguration(name, configLocation);
- if (c != null) {
- return c;
+ String configName;
+ String prefix = isTest ? TEST_PREFIX : DEFAULT_PREFIX;
+ String [] types = factory.getSupportedTypes();
+ if (types == null) {
+ continue;
+ }
+
+ for (String suffix : types) {
+ if (suffix.equals("*")) {
+ continue;
+ }
+ configName = named ? prefix + name + suffix : prefix + suffix;
+
+ InputSource source = getInputFromResource(configName, loader);
+ if (source != null) {
+ return factory.getConfiguration(source);
+ }
}
}
- return new DefaultConfiguration();
+ return null;
+ }
+
+ public String[] getSupportedTypes() {
+ return null;
+ }
+
+ public Configuration getConfiguration(InputSource source) {
+ return null;
}
}
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java?rev=1205703&r1=1205702&r2=1205703&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java Thu Nov 24 02:07:47 2011
@@ -21,6 +21,7 @@ import org.apache.logging.log4j.core.App
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.layout.PatternLayout;
/**
* The default configuration. It writes all output to the Console using the default logging level
@@ -47,33 +48,15 @@ public class DefaultConfiguration extend
public DefaultConfiguration() {
setName(DEFAULT_NAME);
- Appender appender = new ConsoleAppender("Console", new BasicLayout());
+ Layout layout = PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n",
+ null, null, null);
+ Appender appender = new ConsoleAppender("Console", layout);
addAppender(appender);
LoggerConfig root = getRootLogger();
root.addAppender(appender);
+
String l = System.getProperty(DEFAULT_LEVEL);
Level level = (l != null && Level.valueOf(l) != null) ? Level.valueOf(l) : Level.ERROR;
root.setLevel(level);
}
-
- /**
- * Formats the event using the Message's built-in format.
- */
- public class BasicLayout implements Layout {
- public byte[] format(LogEvent event) {
- return formatAs(event).getBytes();
- }
-
- public String formatAs(LogEvent event) {
- return event.getMessage().getFormattedMessage() + "\n";
- }
-
- public byte[] getHeader() {
- return EMPTY_STRING.getBytes();
- }
-
- public byte[] getFooter() {
- return EMPTY_STRING.getBytes();
- }
- }
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java?rev=1205703&r1=1205702&r2=1205703&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java Thu Nov 24 02:07:47 2011
@@ -20,28 +20,19 @@ import org.apache.logging.log4j.core.con
import org.xml.sax.InputSource;
import java.io.File;
-import java.net.URI;
/**
*
*/
@Plugin(name="JSONConfigurationFactory", type="ConfigurationFactory")
@Order(6)
-public class JSONConfigurationFactory extends XMLConfigurationFactory {
+public class JSONConfigurationFactory extends ConfigurationFactory {
- public static final String DEFAULT_CONFIG_FILE = "log4j2.json";
-
- public static final String TEST_CONFIG_FILE = "log4j2-test.json";
-
- public static final String TEST_PREFIX = "log4j2-test";
-
- public static final String DEFAULT_PREFIX = "log4j2";
-
- public static final String SUFFIX = ".json";
+ public static final String[] SUFFIXES = new String[] {".json", ".jsn"};
private File configFile = null;
- private String[] dependencies = new String[] {
+ private static String[] dependencies = new String[] {
"org.codehaus.jackson.JsonNode",
"org.codehaus.jackson.map.ObjectMapper"
};
@@ -61,34 +52,19 @@ public class JSONConfigurationFactory ex
isActive = true;
}
- public Configuration getConfiguration(String name, URI configLocation) {
- InputSource source = null;
- if (configLocation != null) {
- source = getInputFromURI(configLocation);
- }
- if (source == null) {
- String testName;
- String defaultName;
- boolean named = (name != null && name.length() > 0);
- if (named) {
- testName = TEST_PREFIX + name + SUFFIX;
- defaultName = DEFAULT_PREFIX + name + SUFFIX;
- } else {
- testName = TEST_CONFIG_FILE;
- defaultName = DEFAULT_CONFIG_FILE;
- }
- ClassLoader loader = this.getClass().getClassLoader();
- source = getInputFromSystemProperty(loader, ".json");
- if (source == null) {
- source = getInputFromResource(testName, loader);
- if (source == null) {
- source = getInputFromResource(defaultName, loader);
- }
- if (source == null) {
- return named ? getConfiguration(null, null) : null;
- }
- }
+ @Override
+ protected boolean isActive() {
+ return isActive;
+ }
+
+ public Configuration getConfiguration(InputSource source) {
+ if (!isActive) {
+ return null;
}
return new JSONConfiguration(source, configFile);
}
+
+ public String[] getSupportedTypes() {
+ return SUFFIXES;
+ }
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java?rev=1205703&r1=1205702&r2=1205703&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java Thu Nov 24 02:07:47 2011
@@ -16,21 +16,10 @@
*/
package org.apache.logging.log4j.core.config;
-import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.helpers.FileUtils;
-import org.apache.logging.log4j.core.helpers.Loader;
-import org.apache.logging.log4j.status.StatusLogger;
import org.xml.sax.InputSource;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
import java.net.URI;
-import java.net.URL;
/**
*
@@ -39,109 +28,13 @@ import java.net.URL;
@Order(5)
public class XMLConfigurationFactory extends ConfigurationFactory {
- public static final String CONFIGURATION_FILE_PROPERTY = "log4j.configurationFile";
+ public static final String[] SUFFIXES = new String[] {".xml", "*"};
- public static final String DEFAULT_CONFIG_FILE = "log4j2.xml";
-
- public static final String TEST_CONFIG_FILE = "log4j2-test.xml";
-
- public static final String TEST_PREFIX = "log4j2-test";
-
- public static final String DEFAULT_PREFIX = "log4j2";
-
- public static final String SUFFIX = ".xml";
-
- protected static Logger logger = StatusLogger.getLogger();
-
- private File configFile = null;
-
- public Configuration getConfiguration(String name, URI configLocation) {
- InputSource source = null;
- if (configLocation != null) {
- source = getInputFromURI(configLocation);
- }
- if (source == null) {
- String testName;
- String defaultName;
- boolean named = (name != null && name.length() > 0);
- if (named) {
- testName = TEST_PREFIX + name + SUFFIX;
- defaultName = DEFAULT_PREFIX + name + SUFFIX;
- } else {
- testName = TEST_CONFIG_FILE;
- defaultName = DEFAULT_CONFIG_FILE;
- }
- ClassLoader loader = this.getClass().getClassLoader();
- source = getInputFromSystemProperty(loader, null);
- if (source == null) {
- source = getInputFromResource(testName, loader);
- if (source == null) {
- source = getInputFromResource(defaultName, loader);
- }
- if (source == null) {
- return named ? getConfiguration(null, null) : null;
- }
- }
- }
+ public Configuration getConfiguration(InputSource source) {
return new XMLConfiguration(source, configFile);
}
- protected InputSource getInputFromURI(URI configLocation) {
- configFile = FileUtils.fileFromURI(configLocation);
- if (configFile != null && configFile.exists() && configFile.canRead()) {
- try {
- InputSource source = new InputSource(new FileInputStream(configFile));
- source.setSystemId(configLocation.getPath());
- return source;
- } catch (FileNotFoundException ex) {
- logger.error("Cannot locate file " + configLocation.getPath(), ex);
- }
- }
- try {
- InputSource source = new InputSource(configLocation.toURL().openStream());
- source.setSystemId(configLocation.getPath());
- return source;
- } catch (MalformedURLException ex) {
- logger.error("Invalid URL " + configLocation.toString(), ex);
- } catch (IOException ex) {
- logger.error("Unabled to access " + configLocation.toString(), ex);
- }
- return null;
- }
-
- protected InputSource getInputFromSystemProperty(ClassLoader loader, String suffix) {
- String configFile = System.getProperty(CONFIGURATION_FILE_PROPERTY);
- if (configFile == null || (suffix != null && !configFile.toLowerCase().endsWith(suffix.toLowerCase()))) {
- return null;
- }
- InputSource source;
- try {
- URL url = new URL(configFile);
- source = new InputSource(url.openStream());
- source.setSystemId(configFile);
- return source;
- } catch (Exception ex) {
- source = getInputFromResource(configFile, loader);
- if (source == null) {
- try {
- InputStream is = new FileInputStream(configFile);
- source = new InputSource(is);
- source.setSystemId(configFile);
- } catch (FileNotFoundException fnfe) {
- // Ignore the exception
- }
- }
- }
- return source;
- }
-
- protected InputSource getInputFromResource(String resource, ClassLoader loader) {
- InputStream is = Loader.getResourceAsStream(resource, loader);
- if (is == null) {
- return null;
- }
- InputSource source = new InputSource(is);
- source.setSystemId(resource);
- return source;
+ public String[] getSupportedTypes() {
+ return SUFFIXES;
}
}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java?rev=1205703&r1=1205702&r2=1205703&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java Thu Nov 24 02:07:47 2011
@@ -21,6 +21,7 @@ import org.apache.logging.log4j.core.con
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.xml.sax.InputSource;
import java.net.URI;
@@ -33,16 +34,26 @@ public class BasicConfigurationFactory e
return new BasicConfiguration();
}
+ @Override
+ public String[] getSupportedTypes() {
+ return null;
+ }
+
+ @Override
+ public Configuration getConfiguration(InputSource source) {
+ return null;
+ }
+
public class BasicConfiguration extends BaseConfiguration {
- private static final String DEFAULT_LEVEL = "org.apache.logging.log4j.level";
+ private static final String DEFAULT_LEVEL = "org.apache.logging.log4j.level";
- public BasicConfiguration() {
+ public BasicConfiguration() {
- LoggerConfig root = getRootLogger();
- String l = System.getProperty(DEFAULT_LEVEL);
- Level level = (l != null && Level.valueOf(l) != null) ? Level.valueOf(l) : Level.ERROR;
- root.setLevel(level);
+ LoggerConfig root = getRootLogger();
+ String l = System.getProperty(DEFAULT_LEVEL);
+ Level level = (l != null && Level.valueOf(l) != null) ? Level.valueOf(l) : Level.ERROR;
+ root.setLevel(level);
+ }
}
}
-}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicLoggingTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicLoggingTest.java?rev=1205703&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicLoggingTest.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicLoggingTest.java Thu Nov 24 02:07:47 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.core;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class BasicLoggingTest {
+
+ @Test
+ public void test1() {
+ Logger logger = LogManager.getLogger(BasicLoggingTest.class.getName());
+ logger.debug("debug not set");
+ logger.error("Test message");
+ }
+}
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml?rev=1205703&r1=1205702&r2=1205703&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml Thu Nov 24 02:07:47 2011
@@ -19,7 +19,7 @@
org.apache.maven.skinsmaven-fluido-skin
- 1.0-SNAPSHOT
+ 1.0
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/configuration.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/configuration.xml?rev=1205703&r1=1205702&r2=1205703&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/configuration.xml (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/configuration.xml Thu Nov 24 02:07:47 2011
@@ -24,7 +24,163 @@
+
Inserting log requests into the application code requires a fair
+ amount of planning and effort. Observation shows that approximately 4
+ percent of code is dedicated to logging. Consequently, even moderately
+ sized applications will have thousands of logging statements embedded
+ within their code. Given their number, it becomes imperative to
+ manage these log statements without the need to modify them manually.
+
+
+ Configuration of Log4j 2 can be accomplished in 1 of 4 ways:
+
+
Through a configuration file written in XML or JSON.
+
Programmatically, by creating a ConfigurationFactory and Configuration implementation.
+
Programmatically, by calling the APIs exposed in the Configuration interface to add
+ components to the default configuration.
+
Programmatically, by calling methods on the internal Logger class.
+
+ This page focuses primarily on configuring Log4j through a configuration file. Information on
+ programmatically configuring Log4j can be found at Extending Log4j 2.
+
+
+ Note that unlike Log4j 1.x, the public Log4j 2 API does not expose methods to add, modify or remove
+ appenders and filters or manipulate the configuration in any way.
+
+
+
+ Log4j has the ability to automatically configure itself during initialization.
+ When Log4j starts it will locate all the ConfigurationFactory plugins and arrange then in weighted
+ order from highest to lowest. As delivered, Log4j contains two ConfigurationFactory implementations,
+ one for JSON and one for XML.
+
+
Log4j will inspect the "log4j.configurationFile" system property and, if set, will attempt to
+ load the configuration using the ConfigurationFactory that matches the file
+ extension.
+
If no system property is set the JSON ConfigurationFactory will look for log4j-test.json or
+ log4j-test.jsn in the classpath.
+
If no such file is found the XML ConfigurationFactory will look for log4j-test.xml in the
+ classpath.
+
If a test file cannot be located the JSON ConfigurationFactory will look for log4j.json or log4j.jsn
+ on the classpath.
+
If a JSON file cannot be located the XML ConfigurationFactory will try to locate
+ log4j.xml on the classpath.
+
If no configuration file could be located the DefaultConfiguration will
+ be used. This will cause logging output to go to the console.
+
+
+
An example application named MyApp that uses log4j can be used to illustrate how
+ this is done.
+
+
+
+
+
+
+ MyApp begins by importing log4j related classes. It
+ then defines a static logger variable with the name MyApp
+ which happens to be the fully qualified name of the class.
+
+
+
+ MyApp uses the Bar class defined in the packagecom.foo.
+
+
+
+
+
+
+
+ If no configuration files are present logback will default to the DefaultConfiguration which
+ will set up a minimal logging environment consisting of a ConsoleAppender attached
+ to the root logger. The output will be formatted using a
+ PatternLayout set to the pattern "%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n".
+
+
+
+ Note that by default, the root logger is assigned to Level.ERROR.
+
+
+
The output of MyApp would be similar to:
+
+ 17:13:01.540 [main] ERROR com.foo.Bar - Did it again!
+
+
+
+ As was described previously, Log4j will first attempt to configure itself from configuration files. A
+ configuration equivalent to the default would look like:
+
+ Once the file above is placed into the classpath as log4j.xml you will get results identical to
+ those listed above. Changing the root level to trace will result in results similar to:
+