Discussion:
log4j.configuration system property not taken into account?
Gvd
2008-08-29 14:04:45 UTC
Permalink
great !
now it works !!!!
no this brings no help.
anyway, i receive some other error info now.
although it still does not work.
Any Suggestions?
java -Dlog4j.debug=true
-Dlog4j.configuration="C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml"
src.MainClass
log4j: Trying to find
[C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml]
...
start
log4j:WARN No appenders could be found for logger (Testappender).
log4j:WARN Please initialize the log4j system properly.
end
Ah, got it -- and now I remember having been bitten by this myself as
well.
You'll need to prefix the configuration path by "file:", that is, use
java -Dlog4j.debug=true
-Dlog4j.configuration="file:C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml"
src.MainClass
as your command line.
Also, http://logging.apache.org/log4j/1.2/manual.html seems in "Example 4"
to recommend use of forward slashes in the file paths, so modifying from
java -Dlog4j.debug=true
-Dlog4j.configuration="file:/C:/Work/03_eclipse_3_3_0/workspace/Log4j128Tester/conf/log4j.xml"
src.MainClass
--
..Juha
---------------------------------------------------------------------
--
View this message in context: http://www.nabble.com/log4j.configuration-system-property-not-taken-into-account--tp19219001p19220603.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
Gvd
2008-08-29 12:34:31 UTC
Permalink
Hello,

On http://logging.apache.org/log4j/1.2/manual.html I read that the location
of the log4j configuration file can be specified by setting the
log4j.configuration system property in advance with the path to that file.

However, when I start my small test application with the following VM
arguments (in eclipse), it seems not to read the log4j file.
-Dlog4j.configuration=C:\eclipse\workspace\Log4j128Tester\conf\log4j.xml
I have thus everything configured in a log4j.xml file.

My log4j.xml file contains the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="file" class="org.apache.log4j.RollingFileAppender">



<!---->
<layout class="org.apache.log4j.PatternLayout">

</layout>
</appender>

<logger name="Testappender" additivity="false">
<level value="debug" />
<appender-ref ref="file" />
</logger>

</log4j:configuration>

my code is the following:
package src;

import org.apache.log4j.*;

public class MainClass {

public static void main(String[] args) {

//System.out.println(System.getProperty("log4j.configuration"));

Logger lg = Logger.getLogger("Testappender");

System.out.println("start");

lg.debug("test log");
lg.info("test info");
lg.fatal("test fatal");
lg.warn("test warn");

System.out.println("end");

}

}

Am I missing something or am i doing something wrong?
Because I always receive the following error:
log4j:WARN No appenders could be found for logger (Testappender).
log4j:WARN Please initialize the log4j system properly.

Of course, when I put the folder of the log4j.xml in the classpath, it
works.
But this is not what we want.
We want to make it work with the log4j.configuration system property.

Any suggestions?
--
View this message in context: http://www.nabble.com/log4j.configuration-system-property-not-taken-into-account--tp19219001p19219001.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
Juha Laiho
2008-08-29 12:42:46 UTC
Permalink
Post by Gvd
On http://logging.apache.org/log4j/1.2/manual.html I read that the location
of the log4j configuration file can be specified by setting the
log4j.configuration system property in advance with the path to that file.
However, when I start my small test application with the following VM
arguments (in eclipse), it seems not to read the log4j file.
-Dlog4j.configuration=C:\eclipse\workspace\Log4j128Tester\conf\log4j.xml
...
Post by Gvd
Am I missing something or am i doing something wrong?
log4j:WARN No appenders could be found for logger (Testappender).
log4j:WARN Please initialize the log4j system properly.
Of course, when I put the folder of the log4j.xml in the classpath, it
works.
But this is not what we want.
We want to make it work with the log4j.configuration system property.
Any suggestions?
You might try running your test application with log4j debugging enabled
(add -Dlog4j.debug=true to startup parameters). This should show quite
a lot of information about log4j configuration loading and other startup.

Another thing, are you certain it's not Eclipse playing tricks on you --
in other words, have you tried running your test app from the command
prompt?
--
..Juha
Gvd
2008-08-29 13:22:04 UTC
Permalink
no this brings no help.
anyway, i receive some other error info now.
although it still does not work.
Any Suggestions?

java -Dlog4j.debug=true
-Dlog4j.configuration="C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml"
src.MainClass
log4j: Trying to find
[C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml]
using context classloader sun.misc.Launcher$***@133056f.
log4j: Trying to find
[C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml]
using sun.misc.Launcher$***@133056f class loader.
log4j: Trying to find
[C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml]
using ClassLoader.getSystemResource().
log4j: Could not find resource:
[C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml].
start
log4j:WARN No appenders could be found for logger (Testappender).
log4j:WARN Please initialize the log4j system properly.
end
Post by Juha Laiho
Post by Gvd
On http://logging.apache.org/log4j/1.2/manual.html I read that the location
of the log4j configuration file can be specified by setting the
log4j.configuration system property in advance with the path to that file.
However, when I start my small test application with the following VM
arguments (in eclipse), it seems not to read the log4j file.
-Dlog4j.configuration=C:\eclipse\workspace\Log4j128Tester\conf\log4j.xml
...
Post by Gvd
Am I missing something or am i doing something wrong?
log4j:WARN No appenders could be found for logger (Testappender).
log4j:WARN Please initialize the log4j system properly.
Of course, when I put the folder of the log4j.xml in the classpath, it
works.
But this is not what we want.
We want to make it work with the log4j.configuration system property.
Any suggestions?
You might try running your test application with log4j debugging enabled
(add -Dlog4j.debug=true to startup parameters). This should show quite
a lot of information about log4j configuration loading and other startup.
Another thing, are you certain it's not Eclipse playing tricks on you --
in other words, have you tried running your test app from the command
prompt?
--
..Juha
---------------------------------------------------------------------
--
View this message in context: http://www.nabble.com/log4j.configuration-system-property-not-taken-into-account--tp19219001p19219809.html
Sent from the Log4j - Users mailing list archive at Nabble.com.
Juha Laiho
2008-08-29 13:53:34 UTC
Permalink
no this brings no help.
anyway, i receive some other error info now.
although it still does not work.
Any Suggestions?
java -Dlog4j.debug=true
-Dlog4j.configuration="C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml"
src.MainClass
log4j: Trying to find
[C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml]
...
start
log4j:WARN No appenders could be found for logger (Testappender).
log4j:WARN Please initialize the log4j system properly.
end
Ah, got it -- and now I remember having been bitten by this myself as well.
You'll need to prefix the configuration path by "file:", that is, use
java -Dlog4j.debug=true -Dlog4j.configuration="file:C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml" src.MainClass
as your command line.

Also, http://logging.apache.org/log4j/1.2/manual.html seems in "Example 4"
to recommend use of forward slashes in the file paths, so modifying from the above:
java -Dlog4j.debug=true -Dlog4j.configuration="file:/C:/Work/03_eclipse_3_3_0/workspace/Log4j128Tester/conf/log4j.xml" src.MainClass
--
..Juha
Thorbjørn Ravn Andersen
2008-08-29 16:12:22 UTC
Permalink
no this brings no help.
anyway, i receive some other error info now.
although it still does not work.
Any Suggestions?
java -Dlog4j.debug=true
-Dlog4j.configuration="C:\\Work\\03_eclipse_3_3_0\\workspace\\Log4j128Tester\\conf\\log4j.xml"
Try with \ or / instead of \\.

It looks like these backquotes do not need to be doubled.
--
Thorbjørn Ravn Andersen "... plus... Tubular Bells!"
Continue reading on narkive:
Loading...