Author: rjung Date: Mon Dec 8 20:51:01 2014 New Revision: 1643912 URL: http://svn.apache.org/r1643912 Log: Add support for Log4J2 to juli.
Log4J2 has builtin support for commons logging. But using that would mean the Log4J2 jar files have to be put on the CLASSPATH. One can instead integrate Log4J2 similar to Log4J and the code is very similar to what is in org.apache.logging.log4j.jcl. Needs documentation. Probably a candidate for upstream (commons logging). Added: tomcat/trunk/res/patches/ tomcat/trunk/res/patches/commons-logging-log4j2.patch (with props) Modified: tomcat/trunk/build.properties.default tomcat/trunk/build.xml Modified: tomcat/trunk/build.properties.default URL: http://svn.apache.org/viewvc/tomcat/trunk/build.properties.default?rev=1643912&r1=1643911&r2=1643912&view=diff ============================================================================== --- tomcat/trunk/build.properties.default (original) +++ tomcat/trunk/build.properties.default Mon Dec 8 20:51:01 2014 @@ -92,7 +92,7 @@ base-maven.loc=http://repo.maven.apache. # - log4j # - logkit # - servletapi -commons-logging.version=1.1.3 +commons-logging.version=1.2 commons-logging.home=${base.path}/commons-logging-${commons-logging.version} commons-logging-src.loc.1=${base-commons.loc.1}/logging/source/commons-logging-${commons-logging.version}-src.tar.gz commons-logging-src.loc.2=${base-commons.loc.2}/logging/source/commons-logging-${commons-logging.version}-src.tar.gz @@ -104,6 +104,14 @@ avalon-framework.home=${base.path}/avalo avalon-framework.loc=${base-maven.loc}/avalon-framework/avalon-framework/${avalon-framework.version}/avalon-framework-${avalon-framework.version}.jar avalon-framework.jar=${avalon-framework.home}/avalon-framework-${avalon-framework.version}.jar +# ----- log4j2 (required by our extension of commons logging) ----- +log4j2.version=2.1 +log4j2.home=${base.path}/log4j2-${log4j2.version} +log4j2-api.loc=${base-maven.loc}/org/apache/logging/log4j/log4j-api/${log4j2.version}/log4j-api-${log4j2.version}.jar +log4j2-core.loc=${base-maven.loc}/org/apache/logging/log4j/log4j-core/${log4j2.version}/log4j-core-${log4j2.version}.jar +log4j2-api.jar=${log4j2.home}/log4j-api-${log4j2.version}.jar +log4j2-core.jar=${log4j2.home}/log4j-core-${log4j2.version}.jar + # ----- log4j (required by commons logging) ----- log4j.version=1.2.17 log4j.home=${base.path}/log4j-${log4j.version} Modified: tomcat/trunk/build.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/build.xml?rev=1643912&r1=1643911&r2=1643912&view=diff ============================================================================== --- tomcat/trunk/build.xml (original) +++ tomcat/trunk/build.xml Mon Dec 8 20:51:01 2014 @@ -1529,6 +1529,18 @@ </antcall> <antcall target="downloadfile"> + <param name="sourcefile" value="${log4j2-api.loc}"/> + <param name="destfile" value="${log4j2-api.jar}"/> + <param name="destdir" value="${log4j.home}"/> + </antcall> + + <antcall target="downloadfile"> + <param name="sourcefile" value="${log4j2-core.loc}"/> + <param name="destfile" value="${log4j2-core.jar}"/> + <param name="destdir" value="${log4j.home}"/> + </antcall> + + <antcall target="downloadfile"> <param name="sourcefile" value="${log4j.loc}"/> <param name="destfile" value="${log4j.jar}"/> <param name="destdir" value="${log4j.home}"/> @@ -1577,8 +1589,15 @@ <copy tofile="${tomcat.extras}/logging/commons-logging-${commons-logging.version}-src/build2.xml" file="${tomcat.extras}/logging/commons-logging-${commons-logging.version}-src/build.xml" /> + <patch dir="${tomcat.extras}/logging/commons-logging-${commons-logging.version}-src" + patchfile="${basedir}/res/patches/commons-logging-log4j2.patch" + strip="0" + failonerror="true"/> + <copy todir="${tomcat.extras}/logging/commons-logging-${commons-logging.version}-src"> <fileset file="${avalon-framework.jar}" /> + <fileset file="${log4j2-api.jar}" /> + <fileset file="${log4j2-core.jar}" /> <fileset file="${log4j.jar}" /> <fileset file="${logkit.jar}" /> <fileset file="${servletapi.jar}" /> Added: tomcat/trunk/res/patches/commons-logging-log4j2.patch URL: http://svn.apache.org/viewvc/tomcat/trunk/res/patches/commons-logging-log4j2.patch?rev=1643912&view=auto ============================================================================== --- tomcat/trunk/res/patches/commons-logging-log4j2.patch (added) +++ tomcat/trunk/res/patches/commons-logging-log4j2.patch Mon Dec 8 20:51:01 2014 @@ -0,0 +1,358 @@ +Index: build2.xml +=================================================================== +--- build2.xml 2014-12-08 09:08:58.752474000 +0100 ++++ build2.xml 2014-12-06 23:21:57.919049000 +0100 +@@ -76,6 +76,7 @@ + <property name="junit.jar" value="junit-3.8.1.jar"/> + <property name="log4j12.jar" value="log4j-1.2.17.jar"/> + <property name="log4j13.jar" value="log4j-1.3.0.jar"/> ++ <property name="log4j2.jar" value="log4j-api-2.1.jar"/> + <property name="logkit.jar" value="logkit-1.0.1.jar"/> + <property name="avalon-framework.jar" value="avalon-framework-4.1.5.jar"/> + <property name="servletapi.jar" value="servletapi-2.3.jar"/> +@@ -191,10 +192,19 @@ + <pathelement location="${log4j12.jar}"/> + </path> + ++ <!-- Construct unit test classpath (Log4J2 tests) --> ++ <path id="test.classpath.log4j2"> ++ <pathelement location="${build.home}/classes"/> ++ <pathelement location="${build.home}/tests"/> ++ <pathelement location="${junit.jar}"/> ++ <pathelement location="${log4j2.jar}"/> ++ </path> ++ + <!-- Construct javadoc classpath --> + <path id="javadoc.classpath"> + <path refid="compile.classpath"/> + <pathelement location="${log4j12.jar}"/> ++ <pathelement location="${log4j2.jar}"/> + </path> + + <!-- Should all tests fail if one does? --> +@@ -207,6 +217,7 @@ + <property name="test.sysprops.testclasses" value="${build.home}/tests"/> + <property name="test.sysprops.log4j12" value="${log4j12.jar}"/> + <property name="test.sysprops.log4j13" value="${log4j13.jar}"/> ++ <property name="test.sysprops.log4j2" value="${log4j2.jar}"/> + <property name="test.sysprops.logkit" value="${logkit.jar}"/> + <property name="test.sysprops.servlet-api" value="${servletapi.jar}"/> + <property name="test.sysprops.commons-logging" value="${build.home}/${core.jar.name}"/> +@@ -230,6 +241,7 @@ + <get dest="lib/logkit-1.0.1.jar" src="${getlibs.base}/logkit/jars/logkit-1.0.1.jar"/> + <get dest="lib/avalon-framework-4.1.3.jar" src="${getlibs.base}/avalon-framework/jars/avalon-framework-4.1.3.jar"/> + <get dest="lib/log4j-1.2.12.jar" src="${getlibs.base}/log4j/jars/log4j-1.2.12.jar"/> ++ <get dest="lib/log4j-api-2.1.jar" src="${getlibs.base}/log4j/jars/log4j-api-2.1.jar"/> + <get dest="lib/servletapi-2.3.jar" src="${getlibs.base}/servletapi/jars/servletapi-2.3.jar"/> + </target> + +@@ -248,6 +260,7 @@ + Log4j12: ${log4j12.jar} + <!-- Note: log4j13 support is not available in the 1.1 release. --> + <!--Log4j13: ${log4j13.jar}--> ++ Log4j2: ${log4j2.jar} + LogKit: ${logkit.jar} + Avalon-Framework: ${avalon-framework.jar} + </echo> +@@ -285,6 +298,7 @@ + + <available file="${log4j12.jar}" property="log4j12.present"/> + <available file="${log4j13.jar}" property="log4j13.present"/> ++ <available file="${log4j2.jar}" property="log4j2.present"/> + <available file="${build.home}/docs" property="maven.generated.docs.present"/> + </target> + +@@ -308,6 +322,13 @@ + --> + </target> + ++ <target name="log4j2-warning" unless='log4j2.present' depends='init,discovery'> ++ <echo> ++ *** WARNING *** ++ Log4j 2 not found: Cannot Build Log4jLog ++ </echo> ++ </target> ++ + <target name="logkit-warning" unless='logkit.present' depends='init,discovery'> + <echo> + *** WARNING *** +@@ -336,17 +357,25 @@ + </echo> + </target> + ++ <target name="log4j2-test-warning" unless='log4j2.jar' depends='init,discovery'> ++ <echo> ++ *** WARNING *** ++ Log4J 2.x Jar not found: Cannot execute 2.x tests ++ </echo> ++ </target> ++ + <target name='warning' +- depends='log4j12-warning,log4j13-warning,logkit-warning,jdk1.4-warning,avalon-framework-warning,compile-1.4'/> ++ depends='log4j12-warning,log4j13-warning,log4j2-warning,logkit-warning,jdk1.4-warning,avalon-framework-warning,compile-1.4'/> + + <target name="compile-only" +- depends="prepare,discovery,warning,show-lib-presence,compile-non-log4j,compile-log4j12,compile-log4j13,build-jar"/> ++ depends="prepare,discovery,warning,show-lib-presence,compile-non-log4j,compile-log4j12,compile-log4j2,compile-log4j13,build-jar"/> + + <target name="show-lib-presence"> + <echo message="jdk.1.4.present=${jdk.1.4.present}"/> + <echo message="log4j12.present=${log4j12.present}"/> + <!-- Note: log4j13 support is not available in the 1.1 release. --> + <!--<echo message="log4j13.present=${log4j13.present}"/>--> ++ <echo message="log4j2.present=${log4j2.present}"/> + <echo message="logkit.present=${logkit.present}"/> + <echo message="avalon-framework.present=${avalon-framework.present}"/> + </target> +@@ -364,6 +393,7 @@ + <classpath refid="compile.classpath"/> + + <exclude name="org/apache/juli/logging/impl/Log4J*.java"/> ++ <exclude name="org/apache/juli/logging/impl/Log4j*.java"/> + + <exclude name="org/apache/juli/logging/impl/Jdk13LumberjackLogger.java" + unless="jdk.1.4.present"/> +@@ -457,6 +487,30 @@ + </javac> + </target> + ++ <target name="compile-log4j2" depends="prepare,discovery"> ++ <!-- compile the log4j1.2 support classes --> ++ <javac srcdir="${source.home}" ++ destdir="${build.home}/classes" ++ debug="${compile.debug}" ++ deprecation="${compile.deprecation}" ++ optimize="${compile.optimize}" ++ source="${source.version}" ++ target="${target.version}"> ++ ++ <classpath refid="compile.classpath"/> ++ <classpath> ++ <!-- ++ <pathelement refid="compile.classpath"/> ++ <classpath refid="compile.classpath"/> ++ --> ++ <pathelement location="${log4j2.jar}"/> ++ </classpath> ++ ++ <include name="org/apache/juli/logging/impl/Log4jLog.java" ++ if="log4j2.present"/> ++ </javac> ++ </target> ++ + <target name="build-jar"> + <copy todir="${build.home}/classes" filtering="on"> + <fileset dir="${source.home}" excludes="**/*.java"/> +@@ -536,6 +590,28 @@ + </target> + + ++ <target name='compile.log4j2.tests' if='log4j2.present'> ++ <javac srcdir="${test.home}" ++ destdir="${build.home}/tests" ++ debug="${compile.debug}" ++ deprecation="${compile.deprecation}" ++ optimize="${compile.optimize}" ++ source="${source.version}" ++ target="${target.version}"> ++ <classpath refid="test.classpath.log4j2"/> ++ <include name='**/log4j/**'/> ++ <!-- NOTE --> ++ <!-- ++ Pathable tests do not reference the Log4J Logger directly ++ but try to load them by reflection from particular loaders. ++ They will therefore fail unless this logger is available. ++ --> ++ <include name='**/pathable/**'/> ++ <!-- END NOTE --> ++ </javac> ++ </target> ++ ++ + <target name='compile.avalon.tests' if='avalon-framework.present'> + <javac srcdir="${test.home}" + destdir="${build.home}/tests" +@@ -586,6 +662,7 @@ + <exclude name='**/logkit/**'/> + </javac> + <antcall target='compile.log4j.tests'/> ++ <antcall target='compile.log4j2.tests'/> + <antcall target='compile.jdk1.4.tests'/> + <antcall target='compile.avalon.tests'/> + <antcall target='compile.logkit.tests'/> +@@ -719,7 +796,7 @@ + - ant -Dtestmatch=**/FooTestCase testall + --> + +- <target name="test" depends="log4j12-test-warning, compile.tests" ++ <target name="test" depends="log4j12-test-warning,log4j2-test-warning, compile.tests" + description="Run all unit tests"> + <echo message="Test output can be found in directory ${build.home}/test-reports."/> + <delete dir="${build.home}/test-reports"/> +Index: src/main/java/org/apache/juli/logging/impl/LogFactoryImpl.java +=================================================================== +--- src/main/java/org/apache/juli/logging/impl/LogFactoryImpl.java 2014-12-08 09:08:58.509385000 +0100 ++++ src/main/java/org/apache/juli/logging/impl/LogFactoryImpl.java 2014-12-08 09:00:53.877527000 +0100 +@@ -41,6 +41,8 @@ + * requested implementation class.</li> + * <li>Use the <code>org.apache.juli.logging.Log</code> system property + * to identify the requested implementation class.</li> ++ * <li>If <em>Log4J2</em> is available, return an instance of ++ * <code>org.apache.juli.logging.impl.Log4jLog</code>.</li> + * <li>If <em>Log4J</em> is available, return an instance of + * <code>org.apache.juli.logging.impl.Log4JLogger</code>.</li> + * <li>If <em>JDK 1.4 or later</em> is available, return an instance of +@@ -63,6 +65,8 @@ + */ + public class LogFactoryImpl extends LogFactory { + ++ /** Log4jLog class name */ ++ private static final String LOGGING_IMPL_LOG4J2_LOGGER = "org.apache.juli.logging.impl.Log4jLog"; + /** Log4JLogger class name */ + private static final String LOGGING_IMPL_LOG4J_LOGGER = "org.apache.juli.logging.impl.Log4JLogger"; + /** Jdk14Logger class name */ +@@ -160,6 +164,7 @@ + * but broken/unusable for some reason. + */ + private static final String[] classesToDiscover = { ++ LOGGING_IMPL_LOG4J2_LOGGER, + LOGGING_IMPL_LOG4J_LOGGER, + "org.apache.juli.logging.impl.Jdk14Logger", + "org.apache.juli.logging.impl.Jdk13LumberjackLogger", +Index: src/main/java/org/apache/juli/logging/impl/Log4jLog.java +=================================================================== +--- src/main/java/org/apache/juli/logging/impl/Log4jLog.java 2014-12-08 09:08:58.509385000 +0100 ++++ src/main/java/org/apache/juli/logging/impl/Log4jLog.java 2014-12-08 09:00:53.877527000 +0100 +@@ -0,0 +1,132 @@ ++/* ++ * 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.juli.logging.impl; ++ ++import java.io.Serializable; ++ ++import org.apache.juli.logging.Log; ++import org.apache.logging.log4j.Level; ++import org.apache.logging.log4j.LogManager; ++import org.apache.logging.log4j.spi.ExtendedLogger; ++import org.apache.logging.log4j.spi.LoggerContext; ++ ++/** ++ * Copied from org.apache.logging.log4j.jcl.Log4jLog with PrivateManager ++ * taken from org.apache.logging.log4j.jcl.LogFactoryImpl. ++ */ ++public class Log4jLog implements Log, Serializable { ++ ++ private static final long serialVersionUID = 1L; ++ private static final String FQCN = Log4jLog.class.getName(); ++ ++ private final ExtendedLogger logger; ++ ++ public Log4jLog(final ExtendedLogger logger) { ++ this.logger = logger; ++ } ++ ++ public Log4jLog(String name) { ++ this.logger = PrivateManager.getExtendedLogger(name); ++ } ++ ++ public boolean isDebugEnabled() { ++ return logger.isEnabled(Level.DEBUG, null, null); ++ } ++ ++ public boolean isErrorEnabled() { ++ return logger.isEnabled(Level.ERROR, null, null); ++ } ++ ++ public boolean isFatalEnabled() { ++ return logger.isEnabled(Level.FATAL, null, null); ++ } ++ ++ public boolean isInfoEnabled() { ++ return logger.isEnabled(Level.INFO, null, null); ++ } ++ ++ public boolean isTraceEnabled() { ++ return logger.isEnabled(Level.TRACE, null, null); ++ } ++ ++ public boolean isWarnEnabled() { ++ return logger.isEnabled(Level.WARN, null, null); ++ } ++ ++ public void trace(final Object message) { ++ logger.logIfEnabled(FQCN, Level.TRACE, null, message, null); ++ } ++ ++ public void trace(final Object message, final Throwable t) { ++ logger.logIfEnabled(FQCN, Level.TRACE, null, message, t); ++ } ++ ++ public void debug(final Object message) { ++ logger.logIfEnabled(FQCN, Level.DEBUG, null, message, null); ++ } ++ ++ public void debug(final Object message, final Throwable t) { ++ logger.logIfEnabled(FQCN, Level.DEBUG, null, message, t); ++ } ++ ++ public void info(final Object message) { ++ logger.logIfEnabled(FQCN, Level.INFO, null, message, null); ++ } ++ ++ public void info(final Object message, final Throwable t) { ++ logger.logIfEnabled(FQCN, Level.INFO, null, message, t); ++ } ++ ++ public void warn(final Object message) { ++ logger.logIfEnabled(FQCN, Level.WARN, null, message, null); ++ } ++ ++ public void warn(final Object message, final Throwable t) { ++ logger.logIfEnabled(FQCN, Level.WARN, null, message, t); ++ } ++ ++ public void error(final Object message) { ++ logger.logIfEnabled(FQCN, Level.ERROR, null, message, null); ++ } ++ ++ public void error(final Object message, final Throwable t) { ++ logger.logIfEnabled(FQCN, Level.ERROR, null, message, t); ++ } ++ ++ public void fatal(final Object message) { ++ logger.logIfEnabled(FQCN, Level.FATAL, null, message, null); ++ } ++ ++ public void fatal(final Object message, final Throwable t) { ++ logger.logIfEnabled(FQCN, Level.FATAL, null, message, t); ++ } ++ ++ /** ++ * The real bridge between commons logging and Log4j. ++ */ ++ private static class PrivateManager extends LogManager { ++ ++ public static LoggerContext getContext() { ++ return getContext(FQCN, false); ++ } ++ ++ public static ExtendedLogger getExtendedLogger(final String name) { ++ return getContext().getLogger(name); ++ } ++ } ++ ++} Propchange: tomcat/trunk/res/patches/commons-logging-log4j2.patch ------------------------------------------------------------------------------ svn:mime-type = text/plain --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org