Hi,

I usually just put my log4j config file in src/test/resources and it works fine.

I would have thought that having your unit tests dependent upon an environment variable would make them non-deterministic. Do you really need to do this?

In any event, other threads have suggested that there are issues with passing system properties to unit tests at the moment.

Steve C.


On 07/06/2006, at 8:23 PM, Toni Price wrote:


When using the surefire plugin with maven 2.0.4, I want to be able to
configure log4j for logging.

I feel as though I have tried every conceivable configuration, but have not yet been able to get log4j output to show up (to either the console or a
file). It appears to be configured from the correct file since this is
output to the console:

log4j:INFO Using URL [file:/<snip...>/target/classes/ log4j_dev.properties]
for automatic log4j configuration of repository named [default].

I'm also pretty sure it's using this configuration file because it honours various settings (e.g. "log4j.debug=TRUE") that I put in it, and the log
output file is created in the location I specify.

However, even though the log file is created, none of my logging statements
show up in it from my unit tests (e.g. logger.debug("some debugging
message"); etc.) -- and nor do they get printed to the console. Here is the
surefire plugin configuration in my pom.xml:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <systemProperties>
      <property>
        <name>log4j.configuration</name>
        <value>log4j_${env}.properties</value>
      </property>
    </systemProperties>
    <useFile>false</useFile>
    <printSummary>true</printSummary>
    <testFailureIgnore>true</testFailureIgnore>
    <includes>
      <include>**/Test*.java</include>
    </includes>
  </configuration>
</plugin>

(the log4j config file name is set at build time via profiles)

I have also tried setting <forkMode>never</forkMode>. Under the
pluginManagement section, I have tried both:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.3-SNAPSHOT</version>
</plugin>

and

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.2</version>
</plugin>

Here is my log4j config:
---------------------------------------------------------------------- -----
log4j.rootLogger=DEBUG, A0, A1

log4j.logger.org.apache.log4j.PropertyConfigurator=WARN
log4j.logger.org.apache.log4j.config.PropertySetter=WARN
log4j.logger.org.apache.log4j.rolling.RollingFileAppender=WARN

log4j.appender.A0=org.apache.log4j.ConsoleAppender
log4j.appender.A0.layout=org.apache.log4j.PatternLayout
log4j.appender.A0.layout.ConversionPattern=%-4r %-5p %-37.37c - %m%n

log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=target/logs/app.log
log4j.appender.A1.MaxFileSize=1000KB
log4j.appender.A1.MaxBackupIndex=1
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%5p %d [%t] %c - %m%n
---------------------------------------------------------------------- -----

Logging is a crucial thing that I really need to implement before going any further with my project. I've searched on google and nabble but as yet not come up with anything that's helped me solve this. Am I missing something
here? Is there something I've misconfigured or left out?

Thanks for any help
Toni

--
View this message in context: http://www.nabble.com/-M2--log4j- output-does-not-display-when-running-surefire-plugin- t1747117.html#a4748873
Sent from the Maven - Users forum at Nabble.com.


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



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

Reply via email to