I want to prevent maven from displaying INFO messages, I want to see only WARNINGS and ERRORS (if any).
How can I achieve this, preferably by changing the command line that calls maven?
I want to prevent maven from displaying INFO messages, I want to see only WARNINGS and ERRORS (if any).
How can I achieve this, preferably by changing the command line that calls maven?
I made a small investigation because I am also interested in the solution.
According to http://books.sonatype.com/mvnref-book/reference/running-sect-options.html#running-sect-verbose-option
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
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.
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.
mvn validate clean install | egrep -v "(^\[INFO\])"
or
mvn validate clean install | egrep -v "(^\[INFO\]|^\[DEBUG\])"
mvn validate clean install | findstr /V /R "^\[INFO\] ^\[DEBUG\]"
You can achieve this with MAVEN_OPTS, for example
MAVEN_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]
The simplest way is to upgrade to Maven 3.3.1 or higher to take advantage of the ${maven.projectBasedir}/.mvn/jvm.config
support.
Then you can use any options from Maven's SL4FJ's SimpleLogger support to configure all loggers or particular loggers. For example, here is a how to make all warning at warn
level, except for a the PMD which is configured to log at error
:
cat .mvn/jvm.config
-Dorg.slf4j.simpleLogger.defaultLogLevel=warn -Dorg.slf4j.simpleLogger.log.net.sourceforge.pmd=error
See here for more details on logging with Maven.
Go to simplelogger.properties
in ${MAVEN_HOME}/conf/logging/
and set the following properties:
org.slf4j.simpleLogger.defaultLogLevel=warn
org.slf4j.simpleLogger.log.Sisu=warn
org.slf4j.simpleLogger.warnLevelString=warn
warn
, not warning
In Debian this worked for me like a charm to change the log level for Maven 3.6 at runtime without having to change the simplelogger.properties
file:
MAVEN_OPTS='-Dorg.slf4j.simpleLogger.defaultLogLevel=error' mvn test
Unfortunately, even with maven 3 the only way to do that is to patch source code.
Here is short instruction how to do that.
Clone or fork Maven 3 repo: "git clone https://github.com/apache/maven-3.git"
Edit org.apache.maven.cli.MavenCli#logging, and change
cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_INFO );
to
cliRequest.request.setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_WARN );
In current snapshot version it's at line 270
Then just run "mvn install", your new maven distro will be located in "apache-maven\target\" folder
See this diff for the reference: https://github.com/ushkinaz/maven-3/commit/cc079aa75ca8c82658c7ff53f18c6caaa32d2131
I have noticed when using the 2.20.1 version of the maven sunfire plugin, all warnings are written down to a dumpstream file. e.g. /myproject/target/surefire-reports/2017-11-11T23-02-19_850.dumpstream
Changing the info
to error
in simplelogging.properties
file will help in achieving your requirement.
Just change the value of the below line
org.slf4j.simpleLogger.defaultLogLevel=info
to
org.slf4j.simpleLogger.defaultLogLevel=error