Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change maven logging level to display only warning and errors?

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?

like image 948
sorin Avatar asked Jan 24 '11 12:01

sorin


People also ask

Which of the below maven command line option is used to log errors or other server problems?

If you want to control Maven's logging level, you can use one of the following three command line options: -e, --errors. Produce execution error messages. -X, --debug.

How do you see the full stack trace of the errors re run maven with the switch?

To view full stack traces, please go to the Settings->Maven and check the 'Print Exception Stack Traces' box.


2 Answers

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.

like image 191
kisp Avatar answered Sep 28 '22 11:09

kisp


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\]" 
like image 41
Tom Avatar answered Sep 28 '22 12:09

Tom