logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lilianne E. Blaze" <lilianne_bl...@tlen.pl>
Subject Small patch for NTEventLogAppender
Date Fri, 12 Oct 2007 00:28:44 GMT
Hello,
I had major problems getting Log4j compiled on Netbeans 6.0 / WinXP.

It was constantly bitching about lack of NTEventLogAppender.dll, even
when I did everything I could think of to turn off the tests during
compilation.

The patch below basically checks for the dll file, and if it's not found
emits a log-log warn and then silently swallows all events.

Could you please consider including it?

Or at least provide some instructions on how to disable that particular
test during the build?

Greetings, Lilianne E. Blaze

Index: NTEventLogAppender.java
--- NTEventLogAppender.java Base (BASE)
+++ NTEventLogAppender.java Locally Modified (Based On LOCAL)
@@ -38,6 +38,7 @@
    @author <a href="mailto:jim_cakalic@na.biomerieux.com">Jim
Cakalic</a> */
 public class NTEventLogAppender extends AppenderSkeleton {
   private int _handle = 0;
+  static private boolean _libLoaded = false;
 
   private String source = null;
   private String server = null;
@@ -73,6 +74,11 @@
       this.layout = layout;
     }
 
+    if( !_libLoaded ) {
+      LogLog.warn("NTEventLogAppender system library is not loaded.
NTEventLogAppender will not work.");
+      return;
+    }
+
     try {
       _handle = registerEventSource(server, source);
     } catch (Exception e) {
@@ -88,7 +94,7 @@
 
   public
   void activateOptions() {
-    if (source != null) {
+    if ( _libLoaded && source != null) {
       try {
    _handle = registerEventSource(server, source);
       } catch (Exception e) {
@@ -101,6 +107,11 @@
 
   public void append(LoggingEvent event) {
 
+    if( !_libLoaded )
+    {
+      return;
+    }
+
     StringBuffer sbuf = new StringBuffer();
 
     sbuf.append(layout.format(event));
@@ -126,9 +137,11 @@
 
   public
   void finalize() {
+    if( _handle != 0 ) {
     deregisterEventSource(_handle);
     _handle = 0;
   }
+  }
 
   /**
      The <b>Source</b> option which names the source of the event. The
@@ -157,6 +170,12 @@
   native private void deregisterEventSource(int handle);
 
   static {
+    try {
     System.loadLibrary("NTEventLogAppender");
+      _libLoaded = true;
   }
+    catch(java.lang.UnsatisfiedLinkError e) {
+      _libLoaded = false;
 }
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message