You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Craig Newlander <cn...@eqtc.com> on 2001/08/23 17:27:33 UTC

log4j wrapper

Hello,

   I'd like to absract log4j from my appilication so I don't have to do a
import org.apache.log4j.* throughout my source files and be dependant on the
Category class.   What is a good method to employ here?

Craig


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


Re: log4j wrapper

Posted by kk...@softalia.com.
hi!

 >    I'd like to absract log4j from my appilication so I don't have to do a
 > import org.apache.log4j.* throughout my source files and be dependant on the
 > Category class.   What is a good method to employ here?

jdk1.4 has such APIs like this:

   Class caller = sun.reflect.Reflection.getCallerClass(3);

which returns the Class of current methods caller^3;
whose name is then used in deciding which categories to pick.

(for now, I'm just parsing output of stack trace from a
locally created java.lang.Throwable object to get the
caller's name+method; there'd be a better way than this?)...

regards,
kenji

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


Re: log4j wrapper

Posted by Don Taylor <do...@yahoo.com>.
--- Craig Newlander <cn...@eqtc.com> wrote:
> Hello,
> 
>    I'd like to absract log4j from my appilication so I don't have to
> do a
> import org.apache.log4j.* throughout my source files and be dependant
> on the
> Category class.   What is a good method to employ here?
> 
> Craig
> 

I created a wrapper class around Category. You're going to create your
debug(), error(), fatal(), info(), and warn() methods in here. You'll
also need a fully-qualified-classname of the wrapper class. So here's
an example:

class Logger {
  private static final String FQCN = Logger.class.getName();

  public static void debug(Class c, Object message) {
    Category.getInstance(c).log(FQCN, Priority.DEBUG, message, null);
  }

  public static void debug(Class c, Object message, Throwable t) {
    Category.getInstance(c).log(FQCN, Priority.DEBUG, message, t);
  }

  /* Continue wrapping all the others... */
};

-- Don

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

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


Re: log4j wrapper

Posted by Jin Zhao <JZ...@Qcorps.com>.
We also have a solution similar with Don's.
Usually a logger will wrapp all the categories we defined.
You pass the category name to the logging method to do the logging  
for that category.

Jin

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