wleana wrote:
Hi,
I have a LogTest program that can successfully write to syslog using Log4J *when I invoke it standalone*, ie. java ***.**.LogTest. But when I do it from ANT/JUnit, there is no log message written.


I tried around, and found that if I add the call PropertyConfigurator.configure("log4j.properties") in my code, then it will write the log message when I run ANT/JUnit.

But why do I need to do it just for ANT/Junit env, while it is not needed when I run it standalone? I don't want to hard code that way in the code.

For the standalone way, I didn't specify log4j.configuration or invoke PropertyConfigurator.configure(..), all I do is to put log4j.properties file in my classpath and it works.

I do not know for certain but is it possible that you did not have the file in your Ant script's <classpath> ?


I have been using Ant and Log4J with JUnit successfully for the past couple of days by doing this:

1. I have a file named "testlogconfig.properties" located at some specified point in my source tree.

2. I have Ant set a system property with <sysproperty> named "log4j.configuration" whose value is the path to my properties file, prepended by the characters: "file://" (so it looks like this:
<property name="test.log4j.config"
location="path/to/properties/file"/>
<junit
...(other attributes go here)...
>
<sysproperty name="log4j.configuration"
value="file://${test.log4j.config}"/>
</junit>
).


3. Log4J automatically checks for this system property and evaluates the value to a URL and searches for the file at that URL. In my case, on Win2k, I had to use the "file://" prefix but I have heard that you don't necessarily have to use that on Unix systems.

Maybe that will help?


Erik



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



Reply via email to