I inhertied a project that is using log4j.  A framework was added that
wraps log4j and now the method is no longer visible in the output.  I
get back the log4j wrapper method.  How can I get back the calling
method?

Scott


The first implementation was to just add the following to each class

 static Category log =
Category.getInstance(requestHandler.class.getName());

And then do something as follows

log.debug("Initializing request handler");

In the log4j.properties is defined as such

log4j.appender.disk.layout=org.apache.log4j.PatternLayout
log4j.appender.disk.layout.ConversionPattern=%d{DATE} [%p] %M - %m%n

And output look like such

18 May 2003 01:12:36,302 [DEBUG] run - 12399 Calling SEEC Component:
CPL_BIZ010

It was changed to use a Logging framework that wraps log4j

public class Logger {

    protected static String categoryName = Logger.class.getName();

    public Logger(String filename){
        init(filename);
    }
    
    private Logger(){}
   
    
    private void init(String filename) {
       
        Properties props = null;
        try {
            props = PropertiesUtils.loadAsResource(filename);
            PropertyConfigurator.configure(props);
            //getCategory(categoryName).info("Log4j initialized using
file :"+filename);

        }catch(ConfigurationException ce){
            getCategory(categoryName).error("log4j properties file '"+
filename +"' not found.  It must be in the CLASSPATH");
                        System.out.println("log4j properties file '"+
filename +"' not found.  It must be in the CLASSPATH");
        }

    }

    public  boolean isDebugEnabled(String categoryName) {
        return getCategory(categoryName).isDebugEnabled();
    }
 
    public  void debug(String categoryName, Object message) {
        getCategory(categoryName).debug(message);
    }
    

    public  void error(String categoryName, Object message) {
        getCategory(categoryName).error(message);
    }
    
    public  void error(String categoryName, Object message, Throwable t)
{
        getCategory(categoryName).error(message,t);
    }
//etc

    protected Category getCategory(String categoryName) {
        return Category.getInstance(categoryName);
    }
    
}

Then in each class something like this 
 protected static final String CLASS_NAME = MyLogic.class.getName();
        Logger.getInstance().debug(CLASS_NAME," process input stream");

Log4jproperties
log4j.appender.disk.layout.ConversionPattern=%d{DATE} [%p] %M - %m%n

Output
05 Jun 2003 07:06:00,069 [DEBUG] debug -  completed reque
st ......


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to