This might make a good wiki entry. I encourage you to enter it if
you get a chance...
http://wiki.apache.org/logging-log4j/UsefulCode
Jake
At 02:53 PM 4/3/2007, you wrote:
>Mark --
>
>Try this:
>
>1) Rename the log4j.xml file that you use for testing to something else,
>perhaps test-log4j.xml. Keep it in the src/test/resources directory.
>
>2) Make sure that you've included a testResource entry in your pom that
>includes the test-log4j.xml file. Something like this:
>
><build>
> <testResources>
> <testResource>
> <directory>src/test/resources</directory>
> <includes>
> <include>test-log4j.xml</include>
> </includes>
> </testResource>
> </testResources>
></build>
>
>This entry will force Maven to copy the test-log4j.xml file from the
>src/test/resources directory to the target/test-classes whenever it
>compiles the test classes.
>
>3) Tell log4j to use your test configuration file during the unit tests.
>This is done by configuring the surefire plugin. More specifically,
>you'll set the "log4j.configuration" system property to
>"test-log4j.xml". Details on configuring the surefire plugin can be
>found at
>http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-pr
>operties.html. Here's what I believe you'll need to configure the
>surefire plugin:
>
><build>
> <plugins>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-surefire-plugin</artifactId>
> <configuration>
> <systemProperties>
> <property>
> <name>log4j.configuration</name>
> <value>test-log4j.xml</value>
> </property>
> </systemProperties>
> </configuration>
> </plugin>
> </plugins>
></build>
>
>Ron Gallagher
>
>-----Original Message-----
>From: Mark Hansen [mailto:marklists@javector.com]
>Sent: Tuesday, April 03, 2007 1:14 PM
>To: log4j-user@logging.apache.org
>Subject: Configuring Log4J with Maven Testing and Production
>
>I use Log4J and build my applications with Maven2. I have a log4j.xml
>config file in the src/main/resources directory so that Maven2 builds it
>
>into the JAR with my application.
>
>However, I have a different log4j.xml that I want to use with the JUnit
>test that run as part of my Maven build process. I'd like to put that
>log4j.xml (testing) in the src/test/resources directory and have it
>overide the production version in src/main/resources. However, Maven
>doesn't seem to work that way. Instead, the production version of
>log4j.xml seems to come first on the testing classpath and therefore
>gets loaded instead of the testing version of log4j.xml.
>
>I'm sure others must have faced this issue. Are there any recommended
>solutions to the problem?
>
>Thanks,
>
>Mark
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org