2015-12-10 16 views
6

私のmavenプロジェクトのsrc/test/resourceslogback.xmlを入れました。私の意図は、私のテストと実際のコードのための別のログバック設定を持つことです。 My logback.xmlは、以下のようになります -junitテストのためのMavenコンソールからのINFOメッセージの削除

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> 
    <encoder> 
     <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> 
    </encoder> 
    </appender> 
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> 
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 
     <!-- Daily rollover --> 
     <fileNamePattern>/tmp/SolrUpdaterTest.%d{yyyy-MM-dd}.log</fileNamePattern> 
     <!-- Keep 7 days' worth of history --> 
     <maxHistory>7</maxHistory> 
    </rollingPolicy> 
    <encoder> 
     <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> 
    </encoder> 
    </appender> 
    <root> 
    <level value="ERROR" /> 
    <appender-ref ref="CONSOLE" /> 
    <appender-ref ref="FILE" /> 
    </root> 
</configuration> 

mvn test私のMavenコンソールをやっている間、私はERROR

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running com.jabong.discovery.importer.solrUpdater.document.attributes.AttributesFastTestSuite 
13:02:58,179 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy] 
13:02:58,179 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml] 
13:02:58,179 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/home/jabong/code/github.com/jabong/voodoo/solrUpdater/target/test-classes/logback.xml] 
13:02:58,180 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs multiple times on the classpath. 
13:02:58,180 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/home/jabong/code/github.com/jabong/voodoo/solrUpdater/target/classes/logback.xml] 
13:02:58,180 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/home/jabong/code/github.com/jabong/voodoo/solrUpdater/target/test-classes/logback.xml] 
13:02:58,264 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set 
13:02:58,269 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender] 
13:02:58,278 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE] 
13:02:58,301 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 
13:02:58,355 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender] 
13:02:58,357 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE] 
13:02:58,375 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used 
13:02:58,377 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern /tmp/SolrUpdaterTest.%d{yyyy-MM-dd}.log for the active file 
13:02:58,382 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/tmp/SolrUpdaterTest.%d{yyyy-MM-dd}.log'. 
13:02:58,382 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight. 
13:02:58,385 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Thu Dec 10 13:02:58 IST 2015 
13:02:58,387 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 
13:02:58,388 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: /tmp/SolrUpdaterTest.2015-12-10.log 
13:02:58,388 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [null] 
13:02:58,390 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - ROOT level set to ERROR 
13:02:58,390 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT] 
13:02:58,391 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to Logger[ROOT] 
13:02:58,391 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration. 
13:02:58,392 |-INFO in [email protected] - Registering current configuration as safe fallback point 

マイポンポンにルートエラーレベルを設定しているにもかかわらず、以下のようにlogback INFOメッセージの多くでいっぱいです。 XMLは以下のようになります -

<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.discovery.importer</groupId> 
    <artifactId>solrUpdater</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>solrUpdater</name> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <runSuite>**/AttributesFastTestSuite.class</runSuite> 
    </properties> 
    <repositories> 
     <repository> 
      <id>com.jabong.discovery.external-repos</id> 
      <url>file://${project.basedir}/libs</url> 
     </repository> 
    </repositories> 
    <url>http://maven.apache.org</url> 
    <dependencies> 
     <dependency> 
      <groupId>com.fasterxml.jackson.core</groupId> 
      <artifactId>jackson-core</artifactId> 
      <version>2.6.1</version> 
     </dependency> 
     <dependency> 
      <groupId>com.fasterxml.jackson.core</groupId> 
      <artifactId>jackson-annotations</artifactId> 
      <version>2.6.1</version> 
     </dependency> 
     <dependency> 
      <groupId>com.fasterxml.jackson.core</groupId> 
      <artifactId>jackson-databind</artifactId> 
      <version>2.6.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>1.7.13</version> 
     </dependency> 
     <dependency> 
      <groupId>com.rabbitmq</groupId> 
      <artifactId>amqp-client</artifactId> 
      <version>3.5.6</version> 
     </dependency> 
     <dependency> 
      <groupId>org.mongodb</groupId> 
      <artifactId>mongo-java-driver</artifactId> 
      <version>3.0.3</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.solr</groupId> 
      <artifactId>solr-solrj</artifactId> 
      <version>5.2.1</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-logging</groupId> 
      <artifactId>commons-logging</artifactId> 
      <version>1.2</version> 
     </dependency> 
     <dependency> 
      <groupId>ch.qos.logback</groupId> 
      <artifactId>logback-classic</artifactId> 
      <version>1.0.13</version> 
     </dependency> 
     <dependency> 
      <groupId>ch.qos.logback</groupId> 
      <artifactId>logback-core</artifactId> 
      <version>1.0.13</version> 
     </dependency> 
     <dependency> 
      <groupId>com.github.arnabk</groupId> 
      <artifactId>java-dogstatsd-client</artifactId> 
      <version>1.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-lang</groupId> 
      <artifactId>commons-lang</artifactId> 
      <version>2.6</version> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.12</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-collections</groupId> 
      <artifactId>commons-collections</artifactId> 
      <version>3.2.2</version> 
     </dependency> 
    </dependencies> 
    <build> 

     <resources> 
      <resource> 
       <directory>src/main/resources</directory> 
      </resource> 
     </resources> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <version>2.3.1</version> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <classpathPrefix>lib/</classpathPrefix> 
          <mainClass>Updater</mainClass> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.dstovall</groupId> 
       <artifactId>onejar-maven-plugin</artifactId> 
       <version>1.4.4</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>one-jar</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <configuration> 
        <includes> 
         <include>${runSuite}</include> 
        </includes> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <pluginRepositories> 
     <pluginRepository> 
      <id>onejar-maven-plugin.googlecode.com</id> 
      <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url> 
     </pluginRepository> 
    </pluginRepositories> 
</project> 

は、いくつかは私はMAVEでlogback INFOを無効にする方法を知らせることができますnコンソール?

答えて

7

あなたはあなたのケースでは

をlogback.xmlする前にパス上に存在している場合

Logbackは、このファイルを使用しています

をテストするためのファイルlogback-のtest.xmlに名前を付ける必要があり、あなたは何のlogback-のtest.xmlを持っていませんが、 2つのファイルlogback.xmlはパス上にあるので、構成を使用せずに問題を強制的に解決します。

+1

これは私がいつも自分にとって当然のことであったものの1つです。答えをありがとう。他の読者のために、ここにいくつかの[documentation](http://logback.qos.ch/manual/configuration.html)があります。 – Mike

関連する問題