Logging level under maven surefire
Asked Answered
C

4

32

I'm unable to adjust java logging's logging level. I'm using maven surefire (mvn test), and trying to adjust from the default INFO to e.g. FINEST.

I have logging.properties file under src/test/resources/logging.properties

after compile, i see under target/test-classes, i see a logging.properties file with the intended config:

java.util.logging.ConsoleHandler.level=FINEST

javax.enterprise.system.container.ejb.level=FINE

...

however the console output from glassfish only have INFO / SEVERE level messages.

Where did I go wrong? or is this another pain in the butt thing with maven?

Chantel answered 15/10, 2010 at 2:31 Comment(2)
I'm a bit confused here. How does glassfish fit into this? I think it's likely you are getting confused between glassfish's logging and the maven unit test logging. What framework is the maven build using for logging?Elated
i'm debugging a unit test that uses the Embedded container in glassfish v3. according to: forums.java.net/jive/thread.jspa?messageID=395759, under reply by 'Marina Vatkina', thats the key to output FINE messages for the EJB container... I guess my question is is my setup correct for java util logging? Or is there extra configuration needed? - not just for this particular instance, but lets say I have a class com.something.Main, and i want to output FINEST messages for it...Chantel
M
10

You need to specifiy your handlers in the logging file

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

then it should work

Mechellemechlin answered 22/10, 2010 at 18:41 Comment(1)
which file? and what about a log4j.xml file syntax?Area
T
19

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>
Theogony answered 5/9, 2012 at 7:54 Comment(2)
Setting -Djava.util.logging.config.file on the maven command line did not work for me, but this did.Reims
Because surefire plugin do not propogate all system properties you passed to maven one the command line to actual unit test executorInoffensive
M
10

You need to specifiy your handlers in the logging file

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

then it should work

Mechellemechlin answered 22/10, 2010 at 18:41 Comment(1)
which file? and what about a log4j.xml file syntax?Area
C
3

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>
Correia answered 27/7, 2011 at 17:40 Comment(0)
K
2

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.

Kerek answered 8/8, 2014 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.