当前位置:  开发笔记 > 编程语言 > 正文

从Maven控制台删除logback`INFO`消息以进行junit测试

如何解决《从Maven控制台删除logback`INFO`消息以进行junit测试》经验,为你挑选了1个好方法。

我把一个logback.xmlsrc/test/resources从我的Maven项目.我的目的是为我的测试和实际代码提供单独的logback配置.My logback.xml如下所示: -



  
    
      %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 
    
  
  
    
      
      /tmp/SolrUpdaterTest.%d{yyyy-MM-dd}.log
      
      7
    
    
      %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
    
  
  
    
    
    
  

虽然mvn test我已经设置了根错误级别,但是在我的maven控制台上堆满了大量的logback INFO消息,如下所示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 ch.qos.logback.classic.joran.JoranConfigurator@dc24521 - Registering current configuration as safe fallback point

我的pom.xml如下所示: -


    4.0.0
    com.jabong.discovery.importer
    solrUpdater
    0.0.1-SNAPSHOT
    solrUpdater
    
        UTF-8
        **/AttributesFastTestSuite.class
    
    
        
            com.jabong.discovery.external-repos
            file://${project.basedir}/libs
        
    
    http://maven.apache.org
    
        
            com.fasterxml.jackson.core
            jackson-core
            2.6.1
        
        
            com.fasterxml.jackson.core
            jackson-annotations
            2.6.1
        
        
            com.fasterxml.jackson.core
            jackson-databind
            2.6.1
        
        
            org.slf4j
            slf4j-api
            1.7.13
        
        
            com.rabbitmq
            amqp-client
            3.5.6
        
        
            org.mongodb
            mongo-java-driver
            3.0.3
        
        
            org.apache.solr
            solr-solrj
            5.2.1
        
        
            commons-logging
            commons-logging
            1.2
        
        
            ch.qos.logback
            logback-classic
            1.0.13
        
        
            ch.qos.logback
            logback-core
            1.0.13
        
        
            com.github.arnabk
            java-dogstatsd-client
            1.0.1
        
        
            commons-lang
            commons-lang
            2.6
        
        
            junit
            junit
            4.12
            test
        
        
            commons-collections
            commons-collections
            3.2.2
        
    
    

        
            
                src/main/resources
            
        
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.8
                    1.8
                
            
            
                org.apache.maven.plugins
                maven-jar-plugin
                2.3.1
                
                    
                        
                            true
                            lib/
                            Updater
                        
                    
                
            
            
                org.dstovall
                onejar-maven-plugin
                1.4.4
                
                    
                        
                            one-jar
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-surefire-plugin
                
                    
                        ${runSuite}
                    
                
            
        
    
    
        
            onejar-maven-plugin.googlecode.com
            http://onejar-maven-plugin.googlecode.com/svn/mavenrepo
        
    

有人可以告诉我如何禁用INFOmaven控制台中的logback ?



1> Prim..:

您应该将文件命名为logback-test.xml以进行测试

如果存在于logback.xml之前的路径上,则Logback使用此文件

在您的情况下,您没有logback-test.xml但路径上有2个文件logback.xml,因此它不使用任何配置来强制您解决问题

推荐阅读
135369一生真爱_890
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有