Return-Path: Delivered-To: apmail-jakarta-log4j-user-archive@jakarta.apache.org Received: (qmail 69518 invoked by uid 500); 5 Sep 2001 10:11:42 -0000 Mailing-List: contact log4j-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: "LOG4J Users Mailing List" Delivered-To: mailing list log4j-user@jakarta.apache.org Received: (qmail 69507 invoked from network); 5 Sep 2001 10:11:41 -0000 X-Apparently-From: Message-ID: <3B96ABB2.D6C7A32F@yahoo.com> Date: Wed, 05 Sep 2001 15:48:18 -0700 From: Naresh Sharma X-Mailer: Mozilla 4.7 [en] (WinNT; I) X-Accept-Language: en MIME-Version: 1.0 To: LOG4J Users Mailing List Subject: Re: making a wrapper for log4j References: <010f01c1359c$28dac200$0200a8c0@trinity> Content-Type: multipart/alternative; boundary="------------66A05391B456A723FBD40E6B" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N --------------66A05391B456A723FBD40E6B Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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); } > } > --------------66A05391B456A723FBD40E6B Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit 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);   }
}
 

--------------66A05391B456A723FBD40E6B-- _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com