tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shay Mandel <shay...@mercury.co.il>
Subject RE: Configuring tomcat with soap and log4j
Date Wed, 05 Sep 2001 11:31:20 GMT
Hi,

You must initialize the log4j system (as the error says). This means you
must have a class of yourself, which is called before you create the first
instance of a category. This class should do something like this:

String log4jConfigFileName = "log4j.properties";
try {
            // do the first initialization of the file
            PropertyConfigurator.configure(log4jConfigFileName);

            // now set a listener for the properties file so if they are
changed, the log4j will reload it.
            // we are using the default wait time set by log4j.
            PropertyConfigurator.configureAndWatch(log4jConfigFile);
        }
        catch (Exception ex ) {
            // log4j config file not found. just print a message to standard
error.
            System.err.println("Can't initialize the log4j. Error reported
by log4j: " + ex.getMessage());
        }

The file log4j.properties should be in your classpath, or you should give a
name which is a full path to this file.

To have a single point of initialization, we created a factory class for the
log4j categories, which is a singleton. You can use it with some small
modifications:

package your.package.name;

import org.apache.log4j.*;

public class Log4jCategoryFactory {
    private static Log4jCategoryFactory _singleton = new
Log4jCategoryFactory();

    /**
     * internal constructor that is used to create a singelton private
object instance.
     */
    private Log4jCategoryFactory() {
           initLogSystem();
    }

    /**
    * init the log system. This will init the log4j and will set the paths
to the log files
    */
    private void initLogSystem(){
	String log4jConfigFile = "log4j.properties";
        try {
            // do the first initialization of the file
            PropertyConfigurator.configure(log4jConfigFile);

            // now set a listener for the properties file so if they are
changed, the log4j will reload it.
            // we are using the default wait time set by log4j.
            PropertyConfigurator.configureAndWatch(log4jConfigFile);
        }
        catch (Exception ex ) {
            // log4j config file not found. just print a message to standard
error.
            System.err.println("Can't initialize the log4j. Error reported
by log4j: " + ex.getMessage());
        }
    }

    /**
     * get a category instance for a given object. Note that this is kind of
havy operation. You better use
     * the Class version to do this.
     * @param   loggedObject  the object you are looking for it's category
     * @return  a log4j Category instance
     * @see #getInstance(java.lang.Class)
     */
    public static Category getInstance( Object loggedObject ) {
        return Category.getInstance(loggedObject.getClass().getName());
    }


    /**
     * get a category instance for a given category name
     * @param   categoryName  the category you are looking for
     * @return  a log4j Category instance
     */
    public static Category getInstance( String categoryName ) {
        return Category.getInstance(categoryName);
    }


    /**
     * get a category instance for a given category name
     * @param   categoryClass  the class to look for it's category
     * @return  a log4j Category instance
     */
    public static Category getInstance( Class categoryClass ) {
        return Category.getInstance(categoryClass);
    }
}

good luck.

Shay.




-----Original Message-----
From: Ram, Kumar [mailto:ram@profitera.com]
Sent: Wednesday, September 05, 2001 8:46 AM
To: 'tomcat-user@jakarta.apache.org'
Subject: Configuring tomcat with soap and log4j


Hi,
	I am trying to configure log4j with tomcat and soap. The
log4j.properties file is in my C:\soap-2.1\webapps\soap\WEB-INF\classes as
stated in the manual.html file that comes with the package. I have tomcat
installed in C:\jakarta-tomcat-3.2.1The soap service works properly and
gives the correct result. However i get the following error. 

log4j:ERROR No appenders could be found for category
(samples.test.SampleUserCheck).
log4j:ERROR Please initialize the log4j system properly. 

Is there anything i am missing or doing wrong ? I have tested log4j with
other java applications which work fine alone. However i am not able to get
it running with tomcat.

Ram

Mime
View raw message