0

I'm trying to use NTEventLogAppender in Tomcat log4j configuration AND in my WebApp log4j configuration:

  • case A) I declare the appender just in Tomcat: it works* !
  • case B) I declare the appender just in my webapp: it works* !
  • case C) I declare the appender in Tomcat and in my webapp: FAILED

*it works mean that I could see related events in Windows event viewer.

My question is how to fix case C? :

  • Tomcat logs are visible into the event viewer but not my webapp logs.
  • NTEventLogAppender static code doesn't work from my webapp startup.

I overrides "NTEventLogAppender" java classe(following implementation) to debug:

  • the first loadLibrary("NTEventLogAppender.amd64.dll") return "already loaded in another classloader" error;
  • then the appender try to load 32bits version ("NTEventLogAppender.dll") without success (cause my host is 64bits).

So I made a hack to this static part to load another DLL from TMP directory:

static {
  LogLog.warn("************************************************ NTEventLogAppender");
  String fileToLoad="C:\\TMP\\nt\\NTEventLogAppender.amd64.dll";
try {
  System.load(fileToLoad);
  LogLog.warn(String.format("load '%s' OK", fileToLoad));
} catch(java.lang.UnsatisfiedLinkError e) {
  LogLog.error(String.format("unable to load %s : %s", fileToLoad, e.getMessage()), e);
}

In this case, load(...) works but I got the following error :

java.lang.UnsatisfiedLinkError: com.mycompany.logger.NTEventLogAppender.registerEventSource(Ljava/lang/String;Ljava/lang/String;)I
at com.mycompany.logger.NTEventLogAppender.registerEventSource(Native Method)
at com.mycompany.logger.NTEventLogAppender.<init>(NTEventLogAppender.java:62)
at com.mycompany.logger.NTEventLogAppender.<init>(NTEventLogAppender.java:32)

Seems like the library is accessible but not the function. Do you have any idea to make NTEventLogAppender accessible from Tomcat and webapp ?

Library is maybe not thread safe ?

For me the appender should be declared one time for all in tomcat configuration, then as described here, I tryed to put DLL into "$CATALINA_HOME/shared/lib" and I add this directory to my java.library.path but it doesn't work : I got no tomcat logs event in event viewer.

Any idea on how to fix it ?

Community
  • 1
  • 1
boly38
  • 1,806
  • 24
  • 29
  • Related: [.dll already loaded in another classloader](http://stackoverflow.com/questions/1030792/dll-already-loaded-in-another-classloader) – jmehrens May 18 '16 at 18:58
  • Thanks I see this question. Tomorrow I will try to loadLibrary and make this error non fatal (avoid to load copy of dll) to see if that works. – boly38 May 18 '16 at 19:00

1 Answers1

0

To fix this issue, We need to remove log4j jar completely from the webapp and keep only one instance of the following files into $CATALINA_BASE\lib\ directory :

  • NTEventLogAppender<*>.dll
  • log4j.properties
  • and log4j-1.2.17.jar

I was thinking that was already done but that was not the case, and grep save my life:

cd webapp\WEB-INF\lib && grep -rnl NTEventLogAppender

The error "already loaded in another classloader" (and other side effects) was due to a dependency of my web app which includes log4j classes :

<dependency><groupId>org.graylog2</groupId><artifactId>gelfj</artifactId><version>1.1.10</version></dependency>

By removing it I was able to use diagnostic appender for my webapp and for tomcat logs.

NB/ (Even with the help of this sample) I was not able to duplicate log4j.properties (one for tomcat and one for my webapp) so I keep only one global configuration file (from tomcat lib directory).

Community
  • 1
  • 1
boly38
  • 1,806
  • 24
  • 29