How to change maven logging level to display only warning and errors?
Answering your question
I made a small investigation because I am also interested in the solution.
Maven command line verbosity options
According to http://books.sonatype.com/mvnref-book/reference/running-sect-options.html#running-sect-verbose-option
- -e for error
- -X for debug
- -q for only error
Maven logging config file
Currently maven 3.1.x uses SLF4J to log to the System.out . You can modify the logging settings at the file:
${MAVEN_HOME}/conf/logging/simplelogger.properties
According to the page : http://maven.apache.org/maven-logging.html
Command line setup
I think you should be able to setup the default Log level of the simple logger via a command line parameter, like this:
$ mvn clean package -Dorg.slf4j.simpleLogger.defaultLogLevel=debug
But I could not get it to work. I guess the only problem with this is, maven picks up the default level from the config file on the classpath. I also tried a couple of other settings via System.properties, but all of them were unsuccessful.
Appendix
You can find the source of slf4j on github here : slf4j github
The source of the simplelogger here : slf4j/jcl-over-slf4j/src/main/java/org/apache/commons/logging/impl/SimpleLog.java
The plexus loader loads the simplelogger.properties
.
Edit: this answer was from 2013, there are probably better ways to do this now, please consider the other answers.
Linux:
mvn validate clean install | egrep -v "(^\[INFO\])"
or
mvn validate clean install | egrep -v "(^\[INFO\]|^\[DEBUG\])"
Windows:
mvn validate clean install | findstr /V /R "^\[INFO\] ^\[DEBUG\]"
You can achieve this with MAVEN_OPTS, for exampleMAVEN_OPTS=-Dorg.slf4j.simpleLogger.defaultLogLevel=warn mvn clean
Rather than putting the system property directly on the command line. (At least for maven 3.3.1.)
Consider using ~/.mavenrc
for setting MAVEN_OPTS
if you would like logging changed for your login across all maven invocations.
If you are using Logback, just put this logback-test.xml
file into src/test/resources
directory:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
you can achieve this by using below in the commandline itself
-e for error
-X for debug
-q for only error
e.g :
mvn test -X -DsomeProperties='SomeValue' [For Debug level Logs]
mvn test -e -DsomeProperties='SomeValue' [For Error level Logs]
mvn test -q -DsomeProperties='SomeValue' [For Only Error Logs]