Mark

I never had much luck passing a file name to the PropertyConfigurator.configure() 
method from a servlet.  I use the version of configure() that takes a Properties 
object as a parameter.  That way I have control over the location of the configuration 
file.  

In the code below you'll see that I use getClass().getResourceAsStream() to load my 
configuration file.  This allows me to put the file in a directory that is in the 
classpath.  Then I use the inputStream returned to load a Properties object.

Hope this helps.

Jud Barr
Principal Financial Group
Des Moines, Iowa

[EMAIL PROTECTED]



// note the use of "/" in front of the file name.  See the API for 
// getResourceAsStream() for details

private String log4JConfigFile = "/Log4JWebLog.properties";

public void configureLog4J() {

    try {
          //  Using getResourceAsStream and loading a properties object gives us
        // more control over the location of the configuration file.
        InputStream is = getClass().getResourceAsStream(log4JConfigFile);
        theProperties = new Properties();
        theProperties.load(is);
        PropertyConfigurator.configure(theProperties);
        is.close();
    } catch (Exception e) {
        // This is the only location we use Standard Out.  This is because
        // we could not configure Log4J so it's not available for logging the message.
        System.out.println("Could not configure logging. " + e);
    }
}

-----Original Message-----
From: Mark Gordon [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 07, 2001 8:54 AM
To: '[EMAIL PROTECTED]'
Subject: FW: log4j property configuration problem


Hi All

I'm posting this message again, as I didn't get a response. 

Any help from the experts out there greatly appreciated.

Thanks

Mark Gordon

-----Original Message-----
From: Mark Gordon 
Sent: 21 November 2001 10:51
To: '[EMAIL PROTECTED]'
Subject: log4j property configuration problem


Hi All

Tried using the instructions from the Log4j manual on using a servlet for
log4j initialisation. Below is code from the example:

public void init() { 
        String prefix = getServletContext().getRealPath("/"); 
        String file = getInitParameter("log4j-init-file"); 
        // if the log4j-init-file is not set, then no point in trying 
        if(file != null) { 
                PropertyConfigurator.configure(prefix+file); 
        } 
}

However getRealPath() doesn't work from within a WAR file. Any suggestions.
I don't want it to be an expanded WAR file, also the solution, if possible,
must be web container independent.

Thanks

Mark 




**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper at LevelSeas for the presence of computer viruses.

**********************************************************************

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

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

Reply via email to