Logging level under maven surefire

老子叫甜甜 提交于 2019-11-28 00:39:27
martin

You need to specifiy your handlers in the logging file

handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler

then it should work

I tried setting java.util.logging.config.file in the MAVEN_OPTS environment variable, which does not work but finally got it working by putting that system property in the pom.xml (and of course creating an appropriate logging.properties in src/test/resources):

    <plugins>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
           <systemProperties>
             <property> 
               <name>java.util.logging.config.file</name>
               <value>src/test/resources/logging.properties</value>
             </property>
           </systemProperties>
        </configuration>
      </plugin>
    </plugins>

try

${build.testOutputDirectory}/logging.properties

Also, I specify this stuff on the command line with surfire-args.

<argLine>${surefire.argLine} ${argLine} -Djava.util.logging.config.file=${build.testOutputDirectory}/logging.properties</argLine>

I was looking at this exact issue, but did not want a project configuration (pom.xml) file change for every time I need specific logging on a test.

The -D property works from maven command line.

Thus you can select the logging configuration file from the command line:

mvn -Djava.util.logging.config.file=`enter filename here` test

If you are using the generic level denominator .level=FINEST be aware that 3rd party logging will also appear at that level.

To disable or set the maven or 3rd party logging to a specific level use explicit log level selection for those classes in the selected log configuration file.

I have a lot of log lines from com.google.inject.....

aug 08, 2014 12:14:33 PM com.google.inject.internal.util.$Stopwatch resetAndLog
FINE: Instance member validation: 3ms
aug 08, 2014 12:14:33 PM com.google.inject.internal.util.$Stopwatch resetAndLog
FINE: Provider verification: 1ms
aug 08, 2014 12:14:33 PM com.google.inject.internal.util.$Stopwatch resetAndLog
FINE: Static member injection: 1ms

So I add:

com.google.inject.level=INFO

to the file. Remember that the level setting is recursive to all subclasses. Thus com.level=NONE will disable all logging for all loggers from the com domain.

Combining this with the test select feature -Dtest=... in the surefire plugin described here is very good for isolating bugs and errors.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!