3 Replies Latest reply on Feb 10, 2003 1:53 AM by pvamstel

    Your own log4j example

    kylev

      I have a very small EJB application that I'm writing as a learning experience and proof of concept (on JBoss 3.0). It makes sense to me to use log4j as a logger for my application. It should be available to my application thanks to the log4j.jar in server/${config}/lib, or at least I assume so.

      I have an abstraction in place to make it so that I don't have to put log4j references in my source files, allowing me to swap out the underlying logging system if I want to at some later date (as long as I maintain the essential interface). com.kylev.little.logger.LittleLogger currently just extends org.apache.log4j.Logger. I also have the necessary LittleLoggerFactory.

      I expect to be able to do this in my EJB's:

      private static LittleLogger logger = (LittleLogger)LittleLogger.getInstance("this.class.name");

      but it throws the dreaded ClassCastException alluded to in log4j documentation. Apparently, part of the solution is to set "log4j.loggerFactory=com.kylev.little.logger.LoggerFactory" in the log4j.properties file. I've done this, but it doesn't appear that the log4j.properties file is being noticed (setting log4.debug=1 has no effect).

      I'm currently deploying my application as a .jar. I've tried with the log4j.properties at the root of the jar, and in META-INF.

      So my questions are: 1) Where should I put the log4j.properties file such that it is in the application's classpath? 2) Does anyone have a working example of a simple logging abstraction facility in an EJB application?

      I'll gladly provide my source code if needed.