logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Debraj Manna <subharaj.ma...@gmail.com>
Subject Override log4j.properties during testing
Date Wed, 15 Jun 2016 13:04:00 GMT
I want to log only the ERROR during testing in maven. For this purpose I
created a file src/test/resources/log4j.properties, which is going to
override the configuration I already have in
src/main/resources/log4j.properties. But this is not working. My
log4j.properties looks like below:-

log4j.rootLogger=ERROR, out, stdout
# CONSOLE appender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}
| %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} -
%X{bundle.version} | %X | %m%n#log4j.logger.org.apache.http=INFO
# File appender
log4j.appender.out=org.apache.log4j.DailyRollingFileAppender
log4j.appender.out.File=/tmp/wf_test.log
log4j.appender.out.DatePattern='.'yyyy-MM-dd
log4j.appender.out.Append=true
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}
| %-5.5p | %-16.16t | %-32.32c{1} | %X{bundle.id} - %X{bundle.name} -
%X{bundle.version} | %X | %m%n

My pom.xml looks like below:-

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.jabong.orchestratorservice</groupId>
    <artifactId>basecomponent</artifactId>
    <version>0.0.1</version>
    <packaging>bundle</packaging>
    <name>basecomponent</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <camel.version>2.16.1</camel.version>
        <jackson.version>2.7.4</jackson.version>
        <jackson.afterburner.version>2.7.1</jackson.afterburner.version>
        <runSuite>**/AllTestSuite.class</runSuite>
        <sonar.host.url>http://sonar:9000/</sonar.host.url>
        <sonar.jdbc.username>sonar</sonar.jdbc.username>
        <sonar.jdbc.password>sonar</sonar.jdbc.password>
        <sonar.jdbc.url>jdbc:mysql://sonar:3306/sonar?useUnicode=true&amp;characterEncoding=utf8</sonar.jdbc.url>
        <sonar.jdbc.driverClassName>com.mysql.jdbc.Driver</sonar.jdbc.driverClassName>
        <sonar.binaries>target</sonar.binaries>
        <sonar.tests>src/test</sonar.tests>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.junit.reportsPath>build/test-reports</sonar.junit.reportsPath>
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
    </properties>

    <dependencies>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.3.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-afterburner</artifactId>
            <version>${jackson.afterburner.version}</version>
        </dependency>

        <dependency>
            <groupId>com.github.arnabk</groupId>
            <artifactId>java-dogstatsd-client</artifactId>
            <version>1.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20151123</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.11</version>
        </dependency>
        <dependency>
            <groupId>org.im4java</groupId>
            <artifactId>im4java</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>
                com.googlecode.maven-java-formatter-plugin
            </groupId>
            <artifactId>maven-java-formatter-plugin</artifactId>
            <version>0.4</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>4.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jdbc</artifactId>
            <version>${camel.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jetty</artifactId>
            <version>${camel.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-http4</artifactId>
            <version>${camel.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-aws</artifactId>
            <version>${camel.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test</artifactId>
            <version>${camel.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock</artifactId>
            <version>1.58</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.javacrumbs.json-unit</groupId>
            <artifactId>json-unit</artifactId>
            <version>1.11.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.scireum</groupId>
            <artifactId>s3ninja</artifactId>
            <version>2.7</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <activation>
                <property>
                    <name>!maven.test.skip</name>
                </property>
            </activation>

            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <excludes>
                            <exclude>**/*.cfg</exclude>
                        </excludes>
                    </resource>
                </resources>
                <testResources>
                    <testResource>

<directory>${project.basedir}/src/test/resources/</directory>
                    </testResource>
                    <testResource>

<directory>${project.basedir}/src/test/resources/config/</directory>
                    </testResource>
                </testResources>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <version>3.3</version>
                            <configuration>
                                <source>1.8</source>
                                <target>1.8</target>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.19.1</version>
                        <configuration>
                            <includes>
                                <include>${runSuite}</include>
                            </includes>
                            <!-- <skipTests>true</skipTests> -->
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.7.0.201403182114</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <destFile>${sonar.jacoco.reportPath}</destFile>
                        </configuration>
                    </plugin>
                    <!-- Documentation at
https://karaf.apache.org/manual/latest/developers-guide/karaf-maven-plugin.html
-->
                    <plugin>
                        <groupId>org.apache.felix</groupId>
                        <artifactId>maven-bundle-plugin</artifactId>
                        <version>3.0.1</version>
                        <extensions>true</extensions>
                        <configuration>
                            <instructions>

<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>

<Bundle-Description>${project.description}</Bundle-Description>

<Import-Package>*;resolution:=optional</Import-Package>
                            </instructions>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>    </project>

But setting log level to ERROR or some other value in log4j.properties is
not making any effect. The actual level is always INFO. I have gone through
this question
<http://stackoverflow.com/questions/4106524/how-to-override-log4j-properties-during-testing>
and
tried modifying my sure-fire plugin configuration but still no luck.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <includes>
            <include>${runSuite}</include>
        </includes>
        <systemPropertyVariables>
            <log4j.configuration>file:src/test/resources/log4j-surefire.properties</log4j.configuration>
        </systemPropertyVariables>
    </configuration></plugin>

Maven version is as below:-

jabongs-MacBook-Pro-4:basecomponent debraj$ mvn -vApache Maven 3.3.9
(bb52d8502b132ec0a5a3f4c09453c07478323dc5;
2015-11-10T22:11:47+05:30)Maven home:
/Users/debraj/Downloads/apache-maven-3.3.9Java version: 1.8.0_77,
vendor: Oracle CorporationJava home:
/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jreDefault
locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.4", arch: "x86_64", family: "mac"

The issue is there only in test config and during the test execution. If
the log level is changed in src/main/resources/log4j.properties then during
the main application run the log level messages are fine.

Can someone let me know what is going wrong?

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message