Ok - here is my wrapper class.
Feel free to critqiue it as long offer imporvements!
Craig
/*
* Logger.java
*
* Created on August 23, 2001, 9:00 AM
*/
package "put your package name here";
import org.apache.log4j.*;
/**
* @author cnewlander
* @version 1.0
*/
public class Logger {
/** This is a wrapper class for log4j
*/
Category c;
/** The name of this wrapper class
*/
static String FQCN = Logger.class.getName();
/** Constructor which returns the root content
*/
public Logger() {
c = Category.getRoot();
}
/** creates a {@link Category} object
* @param name name reference for this category to create
*/
public Logger(Class name) {
c = Category.getInstance(name.getName());
}
/** Clear diagnostics stack
*/
public static void Remove()
NDC.remove();
}
/** pop diagnostics stack
*/
public static void Pop() {
NDC.pop();
}
/** push a msg onto diagnostics stack
* @param msg msg to push onto the NDC
*/
public static void Push( String msg ) {
NDC.push( msg );
}
/** get a String of the diagnostics stack
* @return see NDC
*/
public static String Get() {
return NDC.get();
}
/** Configure
* @param propsFile full path name of properties file
* @param refreshDwell in miliseconds
*/
public static void configureAndWatch( String propsFile, int
refreshDwell ) {
PropertyConfigurator.configureAndWatch( propsFile, refreshDwell );
}
/** log an debug message
* @param msg the message
*/
public void debug(String msg) {
c.log(FQCN, Priority.DEBUG, msg, null);
}
/** log an debug message
* @param msg Wrapper
* @param t a Throwable
*/
public void debug(String msg, Throwable t) {
c.log(FQCN, Priority.DEBUG, msg, t );
}
/** log an error message
* @param msg Wrapper
*/
public void error(String msg) {
c.log(FQCN, Priority.ERROR, msg, null);
}
/** log an error message
* @param msg Wrapper
* @param t a Throwable
*/
public void error(String msg, Throwable t) {
c.log(FQCN, Priority.ERROR, msg, t);
}
/** log an warn message
* @param msg Wrapper
*/
public void warn(String msg) {
c.log(FQCN, Priority.WARN, msg, null);
}
/** log an warn message
* @param msg Wrapper
* @param t a Throwable
*/
public void warn(String msg, Throwable t) {
c.log(FQCN, Priority.WARN, msg, t);
}
/** log an info message
* @param msg Wrapper
*/
public void info(String msg) {
c.log(FQCN, Priority.INFO, msg, null);
}
/** log an info message
* @param msg Wrapper
* @param t a Throwable
*/
public void info(String msg, Throwable t) {
c.log(FQCN, Priority.INFO, msg, t);
}
/** is debugging enabled (use this before debug() )
* @return Wrapper
*/
public boolean isDebugEnabled() {
return c.isDebugEnabled();
}
}
-----Original Message-----
From: Don Taylor [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 23, 2001 1:38 PM
To: LOG4J Users Mailing List
Subject: Re: log4j wrapper
That's why you need to provide the fully-qualified classname. If you
use the wrapper I showed, you will not have this problem. That is, the
class and method name of the wrapper caller, not the wrapper itself,
will be logged. The code which determines the logging method looks one
past the fully-qualified classname in the callstack. Check it out, I
thought it was rather ingenious myself.
-- Don
--- [EMAIL PROTECTED] wrote:
> One piece of warning about wrapping the log4j api's. The code which
> determines the logging method is dependent on that method being the
> last
> method in the call stack prior to the Category logging method.
> Consequently,
> if you wrap the log4j calls, then every logging message will appear
> to be
> coming from the wrapper methods rather than the method requesting the
> log
> message.
> This is only an issue if you want to have access to the extended
> runtime
> information
> (class, method, line number, etc) in your logs.
>
> -Mike Wolf
>
>
>
>
>
> "Craig Newlander" <[EMAIL PROTECTED]>
> 08/23/01 11:27 AM
> Please respond to "LOG4J Users Mailing List"
>
>
> To: "LOG4J Users Mailing List"
> <[EMAIL PROTECTED]>
> cc:
> Subject: 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]