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 2012/10/28 07:06:22 UTC
svn commit: r1402938 - in /logging/log4j/log4j2/trunk: ./
api/src/main/java/org/apache/logging/log4j/ combined/ combined/src/
combined/src/main/ combined/src/main/resources/
combined/src/main/resources/META-INF/ combined/src/test/
combined/src/test/jav...
Author: rgoers
Date: Sun Oct 28 06:06:21 2012
New Revision: 1402938
URL: http://svn.apache.org/viewvc?rev=1402938&view=rev
Log:
Created combined jar to combine API and Core contents for users who only want the Log4j implementation.
Added:
logging/log4j/log4j2/trunk/combined/ (with props)
logging/log4j/log4j2/trunk/combined/pom.xml
logging/log4j/log4j2/trunk/combined/src/
logging/log4j/log4j2/trunk/combined/src/main/
logging/log4j/log4j2/trunk/combined/src/main/resources/
logging/log4j/log4j2/trunk/combined/src/main/resources/META-INF/
logging/log4j/log4j2/trunk/combined/src/main/resources/META-INF/NOTICE
logging/log4j/log4j2/trunk/combined/src/main/resources/log4j2.logManager.properties
logging/log4j/log4j2/trunk/combined/src/test/
logging/log4j/log4j2/trunk/combined/src/test/java/
logging/log4j/log4j2/trunk/combined/src/test/java/org/
logging/log4j/log4j2/trunk/combined/src/test/java/org/apache/
logging/log4j/log4j2/trunk/combined/src/test/java/org/apache/logging/
logging/log4j/log4j2/trunk/combined/src/test/java/org/apache/logging/log4j/
logging/log4j/log4j2/trunk/combined/src/test/java/org/apache/logging/log4j/core/
logging/log4j/log4j2/trunk/combined/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
logging/log4j/log4j2/trunk/combined/src/test/resources/
logging/log4j/log4j2/trunk/combined/src/test/resources/log4j-test2.xml
Modified:
logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java
logging/log4j/log4j2/trunk/dist/pom.xml
logging/log4j/log4j2/trunk/pom.xml
logging/log4j/log4j2/trunk/src/changes/changes.xml
logging/log4j/log4j2/trunk/src/site/xdoc/build.xml.vm
Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java?rev=1402938&r1=1402937&r2=1402938&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java (original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java Sun Oct 28 06:06:21 2012
@@ -64,6 +64,7 @@ public class LogManager {
* be used but this could be extended to allow multiple implementations to be used.
*/
static {
+ // Shortcut binding to force a specific logging implementation.
PropsUtil managerProps = new PropsUtil("log4j2.LogManager.properties");
String factoryClass = managerProps.getStringProperty(FACTORY_PROPERTY_NAME);
ClassLoader cl = findClassLoader();
Propchange: logging/log4j/log4j2/trunk/combined/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Oct 28 06:06:21 2012
@@ -0,0 +1,6 @@
+*.iml
+target
+.settings
+.classpath
+.project
+
Added: logging/log4j/log4j2/trunk/combined/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/combined/pom.xml?rev=1402938&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/combined/pom.xml (added)
+++ logging/log4j/log4j2/trunk/combined/pom.xml Sun Oct 28 06:06:21 2012
@@ -0,0 +1,78 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>log4j</artifactId>
+ <groupId>org.apache.logging.log4j</groupId>
+ <version>2.0-beta3-SNAPSHOT</version>
+ <relativePath>../</relativePath>
+ </parent>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-combined</artifactId>
+ <name>Apache Log4j API and Core</name>
+ <url>http://maven.apache.org</url>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.5.1</version>
+ <executions>
+ <execution>
+ <id>unpack</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <version>${project.version}</version>
+ <type>jar</type>
+ <overWrite>false</overWrite>
+ <outputDirectory>${project.build.directory}/classes</outputDirectory>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <version>${project.version}</version>
+ <type>jar</type>
+ <overWrite>false</overWrite>
+ <outputDirectory>${project.build.directory}/classes</outputDirectory>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ <skipDeploy>true</skipDeploy>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: logging/log4j/log4j2/trunk/combined/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/combined/src/main/resources/META-INF/NOTICE?rev=1402938&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/combined/src/main/resources/META-INF/NOTICE (added)
+++ logging/log4j/log4j2/trunk/combined/src/main/resources/META-INF/NOTICE Sun Oct 28 06:06:21 2012
@@ -0,0 +1,8 @@
+Apache Log4j API and Implementation
+Copyright 1999-2012 Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+ResolverUtil.java
+Copyright 2005-2006 Tim Fennell
Added: logging/log4j/log4j2/trunk/combined/src/main/resources/log4j2.logManager.properties
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/combined/src/main/resources/log4j2.logManager.properties?rev=1402938&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/combined/src/main/resources/log4j2.logManager.properties (added)
+++ logging/log4j/log4j2/trunk/combined/src/main/resources/log4j2.logManager.properties Sun Oct 28 06:06:21 2012
@@ -0,0 +1 @@
+log4j2.loggerContextFactory = org.apache.logging.log4j.core.impl.Log4jContextFactory
\ No newline at end of file
Added: logging/log4j/log4j2/trunk/combined/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/combined/src/test/java/org/apache/logging/log4j/core/LoggerTest.java?rev=1402938&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/combined/src/test/java/org/apache/logging/log4j/core/LoggerTest.java (added)
+++ logging/log4j/log4j2/trunk/combined/src/test/java/org/apache/logging/log4j/core/LoggerTest.java Sun Oct 28 06:06:21 2012
@@ -0,0 +1,160 @@
+/*
+ * 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.MarkerManager;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.XMLConfigurationFactory;
+import org.apache.logging.log4j.message.StructuredDataMessage;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ *
+ */
+public class LoggerTest {
+
+ private static final String CONFIG = "log4j-test2.xml";
+ private static Configuration config;
+ private static ListAppender app;
+ private static LoggerContext ctx;
+
+ @BeforeClass
+ public static void setupClass() {
+ System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ ctx = (LoggerContext) LogManager.getContext(false);
+ config = ctx.getConfiguration();
+ for (Map.Entry<String, Appender> entry : config.getAppenders().entrySet()) {
+ if (entry.getKey().equals("List")) {
+ app = (ListAppender) entry.getValue();
+ break;
+ }
+ }
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ System.clearProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+ ctx.reconfigure();
+ StatusLogger.getLogger().reset();
+ }
+
+ org.apache.logging.log4j.Logger logger = LogManager.getLogger("LoggerTest");
+
+ @Test
+ public void basicFlow() {
+ logger.entry();
+ logger.exit();
+ List<LogEvent> events = app.getEvents();
+ assertTrue("Incorrect number of events. Expected 2, actual " + events.size(), events.size() == 2);
+ app.clear();
+ }
+
+ @Test
+ public void simpleFlow() {
+ logger.entry(CONFIG);
+ logger.exit(0);
+ List<LogEvent> events = app.getEvents();
+ assertTrue("Incorrect number of events. Expected 2, actual " + events.size(), events.size() == 2);
+ app.clear();
+ }
+
+ @Test
+ public void throwing() {
+ logger.throwing(new IllegalArgumentException("Test Exception"));
+ List<LogEvent> events = app.getEvents();
+ assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size() == 1);
+ app.clear();
+ }
+
+ @Test
+ public void catching() {
+ try {
+ throw new NullPointerException();
+ } catch (Exception e) {
+ logger.catching(e);
+ }
+ List<LogEvent> events = app.getEvents();
+ assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size() == 1);
+ app.clear();
+ }
+
+ @Test
+ public void debug() {
+ logger.debug("Debug message");
+ List<LogEvent> events = app.getEvents();
+ assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size() == 1);
+ app.clear();
+ }
+
+ @Test
+ public void debugObject() {
+ logger.debug(new Date());
+ List<LogEvent> events = app.getEvents();
+ assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size() == 1);
+ app.clear();
+ }
+
+ @Test
+ public void debugWithParms() {
+ logger.debug("Hello, {}", "World");
+ List<LogEvent> events = app.getEvents();
+ assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size() == 1);
+ app.clear();
+ }
+
+ @Test
+ public void mdc() {
+
+ ThreadContext.put("TestYear", new Integer(2010).toString());
+ logger.debug("Debug message");
+ ThreadContext.clear();
+ logger.debug("Debug message");
+ List<LogEvent> events = app.getEvents();
+ assertTrue("Incorrect number of events. Expected 2, actual " + events.size(), events.size() == 2);
+ app.clear();
+ }
+
+ @Test
+ public void structuredData() {
+ ThreadContext.put("loginId", "JohnDoe");
+ ThreadContext.put("ipAddress", "192.168.0.120");
+ ThreadContext.put("locale", Locale.US.getDisplayName());
+ StructuredDataMessage msg = new StructuredDataMessage("Audit@18060", "Transfer Complete", "Transfer");
+ msg.put("ToAccount", "123456");
+ msg.put("FromAccount", "123457");
+ msg.put("Amount", "200.00");
+ logger.info(MarkerManager.getMarker("EVENT"), msg);
+ ThreadContext.clear();
+ List<LogEvent> events = app.getEvents();
+ assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size() == 1);
+ app.clear();
+ }
+}
+
Added: logging/log4j/log4j2/trunk/combined/src/test/resources/log4j-test2.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/combined/src/test/resources/log4j-test2.xml?rev=1402938&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/combined/src/test/resources/log4j-test2.xml (added)
+++ logging/log4j/log4j2/trunk/combined/src/test/resources/log4j-test2.xml Sun Oct 28 06:06:21 2012
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<configuration status="debug" name="XMLConfigTest" packages="org.apache.logging.log4j.test">
+ <properties>
+ <property name="filename">target/test.log</property>
+ </properties>
+ <ThresholdFilter level="trace"/>
+
+ <appenders>
+ <Console name="STDOUT">
+ <PatternLayout pattern="%m MDC%X%n"/>
+ <filters>
+ <MarkerFilter marker="FLOW" onMatch="DENY" onMismatch="NEUTRAL"/>
+ <MarkerFilter marker="EXCEPTION" onMatch="DENY" onMismatch="ACCEPT"/>
+ </filters>
+ </Console>
+ <Console name="FLOW">
+ <PatternLayout pattern="%C{1}.%M %m %ex%n"/>
+ <filters>
+ <MarkerFilter marker="FLOW" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
+ <MarkerFilter marker="EXCEPTION" onMatch="ACCEPT" onMismatch="DENY"/>
+ </filters>
+ </Console>
+ <File name="File" fileName="${filename}">
+ <PatternLayout>
+ <pattern>%d %p %C{1.} [%t] %m%n</pattern>
+ </PatternLayout>
+ </File>
+ <List name="List">
+ </List>
+ </appenders>
+
+ <loggers>
+ <logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
+ <ThreadContextMapFilter>
+ <KeyValuePair key="test" value="123"/>
+ </ThreadContextMapFilter>
+ <appender-ref ref="STDOUT"/>
+ </logger>>
+
+ <logger name="org.apache.logging.log4j.test2" level="debug" additivity="false">
+ <appender-ref ref="File"/>
+ </logger>>
+
+ <root level="trace">
+ <appender-ref ref="List"/>
+ </root>
+ </loggers>
+
+</configuration>
\ No newline at end of file
Modified: logging/log4j/log4j2/trunk/dist/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/dist/pom.xml?rev=1402938&r1=1402937&r2=1402938&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/dist/pom.xml (original)
+++ logging/log4j/log4j2/trunk/dist/pom.xml Sun Oct 28 06:06:21 2012
@@ -76,6 +76,11 @@ limitations under the License.
<classifier>tests</classifier>
</dependency>
<dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-combined</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.logging.log4j.adapters</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${project.version}</version>
Modified: logging/log4j/log4j2/trunk/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/pom.xml?rev=1402938&r1=1402937&r2=1402938&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/pom.xml (original)
+++ logging/log4j/log4j2/trunk/pom.xml Sun Oct 28 06:06:21 2012
@@ -463,8 +463,9 @@
</distributionManagement>
<modules>
<module>api</module>
- <module>log4j12-api</module>
<module>core</module>
+ <module>combined</module>
+ <module>log4j12-api</module>
<module>slf4j-impl</module>
<module>jcl-bridge</module>
<module>flume-ng</module>
Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1402938&r1=1402937&r2=1402938&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sun Oct 28 06:06:21 2012
@@ -23,6 +23,9 @@
<body>
<release version="2.0-beta3" date="TBD" description= "Bug fixes and enhancements">
+ <action dev="rgoers" type="update">
+ Created combined jar to combine API and Core contents for users who only want the Log4j implementation.
+ </action>
<action issue="LOG4J2-104" dev="rgoers" type="fix">
Convert LogManager binding to use "regular" java properties instead of XML properties to workaround a
bug in Oracle's xmlparserv2 jar.
Modified: logging/log4j/log4j2/trunk/src/site/xdoc/build.xml.vm
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/build.xml.vm?rev=1402938&r1=1402937&r2=1402938&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/build.xml.vm (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/build.xml.vm Sun Oct 28 06:06:21 2012
@@ -57,8 +57,65 @@
</dependency>
</dependecies>
]]></source>
+ <p>
+ As an alternative, users who always want to use the Log4j 2 implementation of the API may simply use
+ the combined jar.
+ </p>
+ <source><![CDATA[
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-combined</artifactId>
+ <version>${Log4jReleaseVersion}</version>
+ </dependency>
+ </dependecies>
+ ]]></source>
+ </subsection>
+ <subsection name="Optional Components">
+ <p>
+ Log4j 2.x contains several optional components that can be included in an application.
+ </p>
+ <h4>Log4j 1.x</h4>
+ <p>If there are existing components that are written to use Log4j 1.x and it is desired to have this
+ logging routed to Log4j 2 then remove any log4j 1.x dependencies and add the following.
+ </p>
+ <source><![CDATA[
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j.adapters</groupId>
+ <artifactId>log4j12-api</artifactId>
+ <version>${Log4jReleaseVersion}</version>
+ </dependency>
+ </dependecies>
+ ]]></source>
+ <h4>Apache Commons Logging</h4>
+ <p>Commons Logging is used in many components as a way of letting applications choose the specific
+ logging implementation. To route logging from those components into Log4j 2 include the
+ following dependency and do not remove the Commons Logging jar.
+ </p>
+ <source><![CDATA[
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j.adapters</groupId>
+ <artifactId>log4j-jcl</artifactId>
+ <version>${Log4jReleaseVersion}</version>
+ </dependency>
+ </dependecies>
+ ]]></source>
+ <h4>SLF4J</h4>
+ <p>SLF4J is another popular logging API that may be bound to Log4j 2 by including the following
+ dependency along with the SLF4J dependencies.
+ </p>
+ <source><![CDATA[
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j.adapters</groupId>
+ <artifactId>slf4j-impl</artifactId>
+ <version>${Log4jReleaseVersion}</version>
+ </dependency>
+ </dependecies>
+ ]]></source>
</subsection>
-
</section>
</body>
</document>