Author: carnold Date: Wed Jan 25 12:31:51 2006 New Revision: 372308 URL: http://svn.apache.org/viewcvs?rev=372308&view=rev Log: Bug 35452: Restore NTEventLogAppender
Removed: logging/log4j/trunk/src/java/org/apache/log4j/nt/make.bat Modified: logging/log4j/trunk/build.xml logging/log4j/trunk/src/java/org/apache/log4j/nt/NTEventLogAppender.java logging/log4j/trunk/tests/build.xml logging/log4j/trunk/tests/src/java/org/apache/log4j/nt/NTEventLogAppenderTest.java Modified: logging/log4j/trunk/build.xml URL: http://svn.apache.org/viewcvs/logging/log4j/trunk/build.xml?rev=372308&r1=372307&r2=372308&view=diff ============================================================================== --- logging/log4j/trunk/build.xml (original) +++ logging/log4j/trunk/build.xml Wed Jan 25 12:31:51 2006 @@ -62,9 +62,10 @@ <property name="log4j-jms.jar" value="log4j-jms-${version}.jar"/> <property name="log4j-smtp.jar" value="log4j-smtp-${version}.jar"/> <property name="log4j-db.jar" value="log4j-db-${version}.jar"/> + <property name="log4j-nt.jar" value="log4j-nt-${version}.jar"/> - <!-- Destination for documentation files --> + <!-- Destination for documentation files --> <property name="docs.dest" value="./docs"/> <!-- Source directory for xml docs --> <property name="xdocs.src" value="./src/xdocs"/> @@ -254,7 +255,7 @@ </target> <target name="build" description="Compile all log4j components." - depends="init, build.core, build.oro, build.jms, build.smtp, build.db, + depends="init, build.core, build.oro, build.jms, build.smtp, build.db, build.nt, build.examples"/> <target name="requiredepsCheck" @@ -269,13 +270,13 @@ <isset property="javamail-present"/> <isset property="servletAPI-present"/> <isset property="jdbcExtension-present"/> - <isset property="jaxp-present"/> + <isset property="jaxp-present"/> </and> </condition> <fail unless="alldeps.exist"> Some jar files required to perform a full compile of log4j are not available on the classpath. Update build.properties as needed. - </fail> + </fail> </target> <target name="build.core" depends="init, jndiCheck, jaxpCheck"> @@ -293,7 +294,8 @@ ${stem}/rule/LikeRule.java, ${stem}/or/jms/*.java, ${stem}/selector/servlet/*.java, - ${stem}/lbel/**/*.java" + ${stem}/lbel/**/*.java, + ${stem}/nt/**/*.java" deprecation="${deprecation}" debug="${debug}" target="${target}" @@ -509,8 +511,80 @@ </manifest> </jar> </target> - - <target name="log4j-optional.jar" depends="init, build.core"> + + <target name="build.nt" depends="init"> + <mkdir dir="${javac.dest}/"/> + <javac srcdir="${java.source.dir}" + destdir="${javac.dest}" + deprecation="${deprecation}" + debug="${debug}" + includes="${stem}/nt/**.java" + target="${target}" + source="${source}"> + <classpath refid="compile.classpath"/> + </javac> + </target> + + <target name="log4j-nt.jar" depends="build.nt"> + <mkdir dir="${jar.dest}/"/> + <jar jarfile="${jar.dest}/${log4j-nt.jar}" basedir="${javac.dest}" + includes="${stem}/nt/**/*.class"> + <manifest> + <section name="org/apache/log4j/"> + <attribute name="Implementation-Title" value="log4j-nt"/> + <attribute name="Implementation-Version" value="${version}"/> + <attribute name="Implementation-Vendor" value="Apache Software Foundation"/> + </section> + </manifest> + </jar> + </target> + + <target name="build.nt.dll" depends="log4j.jar,log4j-nt.jar" description="Build NTEventLogAppender.dll"> + <javah class="org.apache.log4j.nt.NTEventLogAppender,org.apache.log4j.Priority" + destdir="${javac.dest}" + classpath="${jar.dest}/${log4j.jar};${jar.dest}/${log4j-nt.jar}"/> + <exec executable="mc"> + <arg value="-h"/> + <arg file="${javac.dest}"/> + <arg value="-r"/> + <arg file="${javac.dest}"/> + <arg file="${java.source.dir}org/apache/log4j/nt/EventLogCategories.mc"/> + </exec> + + <exec executable="windres"> + <arg value="-o"/> + <arg file="${javac.dest}/EventLogCategories.o"/> + <arg value="--include-dir=${javac.dest}"/> + <arg file="${javac.dest}/EventLogCategories.rc"/> + </exec> + + <exec executable="windres"> + <arg value="-o"/> + <arg file="${javac.dest}/NTEventLogAppender.o"/> + <arg file="${java.source.dir}org/apache/log4j/nt/NTEventLogAppender.rc"/> + </exec> + + <property name="jni.include.dir" location="${java.home}\..\include"/> + <exec executable="gcc"> + <arg value="-Wall"/> + <arg value="-D_JNI_IMPLEMENTATION_"/> + <arg value="-Wl,--kill-at"/> + <arg value="-I${jni.include.dir}"/> + <arg value="-I${jni.include.dir}\win32"/> + <arg value="-I${javac.dest}"/> + <arg value="-shared"/> + <arg file="${java.source.dir}org/apache/log4j/nt/nteventlog.cpp"/> + <arg file="${javac.dest}/NTEventLogAppender.o"/> + <arg file="${javac.dest}/EventLogCategories.o"/> + <arg value="-o"/> + <arg file="${jar.dest}/NTEventLogAppender.dll"/> + </exec> + + </target> + + + + <target name="log4j-optional.jar" depends="init, build.core"> <mkdir dir="${jar.dest}/"/> <jar jarfile="${jar.dest}/${log4j-optional.jar}" basedir="${javac.dest}" includes="${stem}/net/Multicast*.class, @@ -547,7 +621,7 @@ <!-- ================================================================= --> <target name="jar" depends="log4j.jar, log4j-optional.jar, log4j-jms.jar, log4j-smtp.jar, - log4j-db.jar, log4j-oro.jar, log4j-xml.jar"> + log4j-db.jar, log4j-oro.jar, log4j-xml.jar, log4j-nt.jar"> </target> <!-- ================================================================= --> @@ -601,7 +675,8 @@ ${stem}/net/SocketHub*.class, ${stem}/net/Telnet*.class, ${stem}/pattern/StackPatternConverter.class, - ${stem}/DUMMY.java" + ${stem}/DUMMY.java, + ${stem}/nt/*.class" > <manifest> <attribute name="Manifest-version" value="1.0"/> @@ -827,7 +902,7 @@ <!-- ================================================================= --> <!-- Build a complete distribution. Results go to ${dist.images} --> <!-- ================================================================= --> - <target name="dist" depends="init, clean, requiredepsCheck, javadoc, jar, site"> + <target name="dist" depends="init, clean, requiredepsCheck, javadoc, jar, site, build.nt.dll"> <delete verbose="true"> <fileset dir="."> Modified: logging/log4j/trunk/src/java/org/apache/log4j/nt/NTEventLogAppender.java URL: http://svn.apache.org/viewcvs/logging/log4j/trunk/src/java/org/apache/log4j/nt/NTEventLogAppender.java?rev=372308&r1=372307&r2=372308&view=diff ============================================================================== --- logging/log4j/trunk/src/java/org/apache/log4j/nt/NTEventLogAppender.java (original) +++ logging/log4j/trunk/src/java/org/apache/log4j/nt/NTEventLogAppender.java Wed Jan 25 12:31:51 2006 @@ -1,12 +1,12 @@ /* - * Copyright 1999-2005 The Apache Software Foundation. - * + * Copyright 1999,2005 The Apache Software Foundation. + * * Licensed 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. @@ -16,12 +16,12 @@ package org.apache.log4j.nt; -import org.apache.log4j.*; -import org.apache.log4j.spi.LoggingEvent; +import org.apache.log4j.AppenderSkeleton; +import org.apache.log4j.Layout; import org.apache.log4j.Level; +import org.apache.log4j.PatternLayout; import org.apache.log4j.helpers.LogLog; - -import java.io.*; +import org.apache.log4j.spi.LoggingEvent; /** @@ -37,87 +37,102 @@ @author <a href="mailto:[EMAIL PROTECTED]">Chris Taylor</a> @author <a href="mailto:[EMAIL PROTECTED]">Jim Cakalic</a> */ public class NTEventLogAppender extends AppenderSkeleton { - private int _handle = 0; + private static final int FATAL = Level.FATAL.toInt(); + private static final int ERROR = Level.ERROR.toInt(); + private static final int WARN = Level.WARN.toInt(); + private static final int INFO = Level.INFO.toInt(); + private static final int DEBUG = Level.DEBUG.toInt(); + + static { + System.loadLibrary("NTEventLogAppender"); + } + private int _handle = 0; + private boolean dirty = true; private String source = null; private String server = null; - private static final int FATAL = Level.FATAL.toInt(); - private static final int ERROR = Level.ERROR.toInt(); - private static final int WARN = Level.WARN.toInt(); - private static final int INFO = Level.INFO.toInt(); - private static final int DEBUG = Level.DEBUG.toInt(); - public NTEventLogAppender() { this(null, null, null); } - public NTEventLogAppender(String source) { + public NTEventLogAppender(final String source) { this(null, source, null); } - public NTEventLogAppender(String server, String source) { + public NTEventLogAppender(final String server, final String source) { this(server, source, null); } - public NTEventLogAppender(Layout layout) { + public NTEventLogAppender(final Layout layout) { this(null, null, layout); } - public NTEventLogAppender(String source, Layout layout) { + public NTEventLogAppender(final String source, final Layout layout) { this(null, source, layout); } - public NTEventLogAppender(String server, String source, Layout layout) { + public NTEventLogAppender( + final String server, final String source, final Layout layout) { + super(false); + this.server = server; + if (source == null) { - source = "Log4j"; + this.source = "Log4j"; } + if (layout == null) { - this.layout = new TTCCLayout(); + this.layout = new PatternLayout("%d [%t] %p %c %x %m%n"); } else { this.layout = layout; } - try { - _handle = registerEventSource(server, source); - } catch (Exception e) { - e.printStackTrace(); - _handle = 0; - } + activateOptions(); } - public - void close() { + public void close() { // unregister ... } - public - void activateOptions() { - if (source != null) { + public void activateOptions() { + if (dirty && (source != null)) { + dirty = false; + + if (_handle != 0) { + try { + deregisterEventSource(_handle); + } catch (Exception e) { + getLogger().error("Could not deregister event source.", e); + } + } + try { - _handle = registerEventSource(server, source); + _handle = registerEventSource(server, source); + super.activateOptions(); } catch (Exception e) { - LogLog.error("Could not register event source.", e); - _handle = 0; + getLogger().error("Could not register event source.", e); + _handle = 0; } } } - - public void append(LoggingEvent event) { - + public void append(final LoggingEvent event) { StringBuffer sbuf = new StringBuffer(); sbuf.append(layout.format(event)); - if(layout.ignoresThrowable()) { + + if (layout.ignoresThrowable()) { String[] s = event.getThrowableStrRep(); + if (s != null) { - int len = s.length; - for(int i = 0; i < len; i++) { - sbuf.append(s[i]); - } + int len = s.length; + + for (int i = 0; i < len; i++) { + sbuf.append(s[i]); + } } } + // Normalize the log message level into the supported categories int nt_category = event.getLevel().toInt(); @@ -128,9 +143,7 @@ reportEvent(_handle, sbuf.toString(), nt_category); } - - public - void finalize() { + public void finalize() { deregisterEventSource(_handle); _handle = 0; } @@ -139,29 +152,25 @@ The <b>Source</b> option which names the source of the event. The current value of this constant is <b>Source</b>. */ - public - void setSource(String source) { + public void setSource(final String source) { this.source = source.trim(); + dirty = true; } - public - String getSource() { + public String getSource() { return source; } -/** - The <code>NTEventLogAppender</code> requires a layout. Hence, - this method always returns <code>true</code>. */ - public - boolean requiresLayout() { + /** + The <code>NTEventLogAppender</code> requires a layout. Hence, + this method always returns <code>true</code>. */ + public boolean requiresLayout() { return true; } - native private int registerEventSource(String server, String source); - native private void reportEvent(int handle, String message, int level); - native private void deregisterEventSource(int handle); + private native int registerEventSource(String server, String source); - static { - System.loadLibrary("NTEventLogAppender"); - } + private native void reportEvent(int handle, String message, int level); + + private native void deregisterEventSource(int handle); } Modified: logging/log4j/trunk/tests/build.xml URL: http://svn.apache.org/viewcvs/logging/log4j/trunk/tests/build.xml?rev=372308&r1=372307&r2=372308&view=diff ============================================================================== --- logging/log4j/trunk/tests/build.xml (original) +++ logging/log4j/trunk/tests/build.xml Wed Jan 25 12:31:51 2006 @@ -32,8 +32,8 @@ <!-- distribution directory --> <property name="project.home" value=".."/> <property name="project.dist.dir" value="${project.home}/dist"/> - - <!-- The directory where source files are stored. --> + + <!-- The directory where source files are stored. --> <property name="project.source.home" value="${project.home}/src/java/"/> <property name="project.classes.home" value="${project.dist.dir}/classes/"/> @@ -141,6 +141,7 @@ <ant dir=".." target="build.servletAPI" inheritRefs="false"/> <ant dir=".." target="build.oro" inheritRefs="false"/> <ant dir=".." target="build.smtp" inheritRefs="false"/> + <ant dir=".." target="build.nt" inheritRefs="false"/> </target> <!-- ================================================================= --> @@ -221,6 +222,7 @@ FileWatchdog, CachedDateFormat, Encoding, + NTEventLogAppender, Syslog "/> @@ -747,7 +749,31 @@ </junit> </target> - <target name="Syslog" depends="build"> + <target name="build.nt.init"> + <available file="${project.dist.dir}/lib/NTEventLogAppender.dll" property="nt.dll.available"/> + <condition property="is-windows" value="true"> + <os family="windows"/> + </condition> + </target> + + <target name="build.nt.dll" if="is-windows" unless="nt.dll.available" depends="build.nt.init"> + <ant dir=".." target="build.nt.dll" inheritRefs="false"/> + </target> + + <target name="NTEventLogAppender" depends="build, build.nt.dll" if="is-windows"> + <junit printsummary="yes" + fork="yes" + haltonfailure="${haltonfailure}" + dir="${project.dist.dir}/lib"> + <classpath refid="tests.classpath"/> + <formatter type="plain" usefile="false"/> + <test name="org.apache.log4j.nt.NTEventLogAppenderTest" /> + </junit> + </target> + + + + <target name="Syslog" depends="build"> <junit printsummary="yes" fork="yes" haltonfailure="${haltonfailure}"> <classpath refid="tests.classpath"/> <formatter type="plain" usefile="false"/> Modified: logging/log4j/trunk/tests/src/java/org/apache/log4j/nt/NTEventLogAppenderTest.java URL: http://svn.apache.org/viewcvs/logging/log4j/trunk/tests/src/java/org/apache/log4j/nt/NTEventLogAppenderTest.java?rev=372308&r1=372307&r2=372308&view=diff ============================================================================== --- logging/log4j/trunk/tests/src/java/org/apache/log4j/nt/NTEventLogAppenderTest.java (original) +++ logging/log4j/trunk/tests/src/java/org/apache/log4j/nt/NTEventLogAppenderTest.java Wed Jan 25 12:31:51 2006 @@ -15,11 +15,13 @@ */ package org.apache.log4j.nt; + import junit.framework.TestCase; -import org.apache.log4j.Logger; -import org.apache.log4j.LogManager; -import org.apache.log4j.Level; + import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; /** @@ -29,7 +31,6 @@ * @author Curt Arnold */ public class NTEventLogAppenderTest extends TestCase { - /** * Clean up configuration after each test. */ @@ -42,13 +43,15 @@ */ public void testSimple() { BasicConfigurator.configure(new NTEventLogAppender()); - Logger logger = Logger.getLogger("org.apache.log4j.nt.NTEventLogAppenderTest"); - int i = 0; - logger.debug( "Message " + i++); - logger.info( "Message " + i++); - logger.warn( "Message " + i++); - logger.error( "Message " + i++); + + Logger logger = + Logger.getLogger("org.apache.log4j.nt.NTEventLogAppenderTest"); + int i = 0; + logger.debug("Message " + i++); + logger.info("Message " + i++); + logger.warn("Message " + i++); + logger.error("Message " + i++); logger.log(Level.FATAL, "Message " + i++); - logger.debug("Message " + i++, new Exception("Just testing.")); + logger.debug("Message " + i++, new Exception("Just testing.")); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]