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 Ulrik Sandberg <ul...@purple.se> on 2001/12/20 11:40:03 UTC

URL not needed on UNIX

It seems log4j 1.1.3 doesn't need the property file path to be in URL 
format when running on UNIX, while on Windows98 it's required. 
Am I correct?

Assume the class LogTest.java:

import org.apache.log4j.Category;                                           
                                                                            
public class LogTest {
    private static final Category log = 
        Category.getInstance(LogTest.class);

    public static void main(String[] args) {
        log.error("This is an error message");
    }
}

and the config file log4j.properties:

log4j.rootCategory=DEBUG, F
log4j.appender.F=org.apache.log4j.FileAppender
log4j.appender.F.layout=org.apache.log4j.PatternLayout
log4j.appender.F.layout.ConversionPattern=%d{ABSOLUTE} %m%n
log4j.appender.F.File=logtest.log

Having log4j.jar and log4j.properties in the current dir, this works 
on Solaris7:

% java -cp .:log4j.jar LogTest

Running the same code on Win98 (using the same log4j.jar and 
log4j.properties):

C:\>java -cp .;log4j.jar LogTest
log4j:ERROR No appenders could be found for category (LogTest).
log4j:ERROR Please initialize the log4j system properly.

Specifying the property file doesn't help:

C:\>java -Dlog4j.configuration=log4j.properties -cp .;log4j.jar LogTest
log4j:ERROR No appenders could be found for category (LogTest).
log4j:ERROR Please initialize the log4j system properly.

However, when using a URL path, it succeeds:

C:\>java -Dlog4j.configuration=file:log4j.properties -cp .;log4j.jar LogTest
                               ^^^^^

Debug
=====
Running with -Dlog4j.configDebug results in this on Solaris7:

log4j: Trying to find [log4j.properties] using
sun.misc.Launcher$AppClassLoader@3f52a5 class loader.
log4j: Using URL [file:/users/ulsa/src/logtest/log4j.properties] for automatic
log4j configuration.
log4j: Reading configuration from URL
file:/users/ulsa/src/logtest/log4j.properties

On Win98 without URL:

C:\>java -Dlog4j.configDebug -Dlog4j.configuration=log4j.properties -cp
.;log4j.jar LogTest
log4j: Could not find resource: [log4j.properties].
log4j:ERROR No appenders could be found for category (LogTest).
log4j:ERROR Please initialize the log4j system properly.
...

On Win98 with URL:

C:\>java -Dlog4j.configDebug -Dlog4j.configuration=file:log4j.properties -cp
.;log4j.jar LogTest
log4j: Reading configuration from URL file:log4j.properties
...

--Ulrik Sandberg

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>