Hello ,

Well i guess in this implementation code which will use your logging code has to make call like this in order to log the messages:

Logger logger = new Logger("xyz");
Category cat = logger.getCat();
cat.debug("Hi, this is Debug");
...

I think better way to implement could be like this

Create a interface, which will contain method for logging
Now create a class which will implement above mentioned interface, this class will act as Wrapper over the Log4J API and the code which is using this logging module have to just get the reference of this class and call the method for logging. So any time you can change the implementation if need to do so.

Does this makes sense ????

Anyway i have written the code in crude form below, please comment what do you think.

Creating Interface
public interface Logger {

    public void debug (Object message);

     public void debug (Object message, Throwable exception);

     public void info (Object message);

     public void info (Object message, Throwable exception);

     public void warn (Object message);

     public void warn (Object message, Throwable exception);

     public void error (Object message);

     public void error (Object message, Throwable exception);

     public void fatal (Object message);

     public void fatal (Object message, Throwable exception);
}
 

Creating Wrapper class

public class Log4JLogger implements Logger { // May be we can have Singleton class.

public Log4JLogger() {
    initi();
}

private void init() {
    // Load Log4J config file here.

}

}
 

--
Naresh
 

"G.L. Grobe" wrote:

I'm trying to put a wrapper around the Logging so that I won't have to put log4j imports and declarations all over my code. I've heard of other doing this but I'm not exactly sure how so I was hoping I could get some pointers on what I've done so far. Any help much appreciated. ----package com.neuroquest.cais.log; import org.apache.log4j.Category;
import org.apache.log4j.PropertyConfigurator;public class Logger extends Category {   static Category cat;    public Category getCat() {
      return cat;
   }

   public Logger(String name) {      try {
         PropertyConfigurator.configure("rtlog.properties");
      }
      catch (Exception e) {
         System.err.println("Could not open rtlog.properties");
      }      if (cat == null)
         cat = Category.getInstance(name);   }
}
 

Reply via email to