177

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?

sorin
  • 161,544
  • 178
  • 535
  • 806
  • Relevant topic: http://stackoverflow.com/questions/71069/can-maven-be-made-less-verbose/40535065#40535065 . `-B, --batch-mode` or `-q` will make `mvn` less verbose. – Stanislav Dec 07 '16 at 10:08
  • Possible duplicate of [Is is possible to modify the maven console output to hide the \[INFO\] logging?](https://stackoverflow.com/questions/4116659/is-is-possible-to-modify-the-maven-console-output-to-hide-the-info-logging) – Organic Advocate Aug 24 '19 at 00:14

11 Answers11

139

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.

Community
  • 1
  • 1
kisp
  • 6,402
  • 3
  • 21
  • 19
  • 2
    did you get the `simplelogger.properties` change working? When I change the `org.slf4j.simpleLogger.warnLevelString` setting `mvn compile` updates appropriately, but it appears to be ignoring the `org.slf4j.simpleLogger.defaultLogLevel` setting. It also logs at the info level, even when i set that to warn or error. – Alden Mar 05 '14 at 16:37
  • 1
    @Alden, I am getting the same behaviour. it is simply ignored. – jax Jul 01 '14 at 03:09
  • 22
    For me it turned out that adding "-Dorg.slf4j.simpleLogger.defaultLogLevel=info" to the build command does not have any effect. If I define this before the build in MAVEN_OPTS like this: export "MAVEN_OPTS=$MAVEN_OPTS -Dorg.slf4j.simpleLogger.defaultLogLevel=debug", then it works perfectly without changing the ${MAVEN_HOME}/conf/logging/simplelogger.properties file. – Gábor Lipták Dec 18 '14 at 11:34
  • 1
    Alden, Gábor Lipták: and for me none of the two methods work. :( I am using Maven 3.2.5. – Greg Dubicki Mar 05 '15 at 09:47
  • 1
    if windows, in bat file ,use set MAVEN_OPTS=%MAVEN_OPTS% -Dorg.slf4j.simpleLogger.defaultLogLevel=warn – feilong May 16 '16 at 09:35
  • Bingo, `-X` was overpowering `--quiet` for me. – Sridhar Sarnobat Jul 19 '17 at 21:05
41

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\]"
Tom
  • 3,324
  • 1
  • 31
  • 42
  • 9
    but if the point is to reduce the redundant IO during mvn... then it's not really does the trick – HoaPhan Jul 03 '15 at 19:06
  • How can we achieve the same on Windows machine as egrep doesn't work on it? – hemanto Sep 14 '17 at 04:30
  • something like `mvn validate clean install | findstr /V /B "\[INFO\]" | findstr /V /B "\[WARN\]"` – Tom Sep 14 '17 at 22:10
  • Looks like `findstr` supports regex and other options that might make it more succinct - https://ss64.com/nt/findstr.html – Tom Sep 14 '17 at 22:13
  • `mvn validate clean install | findstr /V /R "^\[INFO\] ^\[WARN\]"` – Tom Sep 14 '17 at 22:19
38

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.

Josmar
  • 584
  • 7
  • 16
binkley
  • 573
  • 1
  • 6
  • 8
  • 2
    This seems to work as I could disable warning and info message by setting the level to error, but unfortunately it also turned off the regular output. I was actually trying to disable some warnings while running `help:evaluate` target to print the value of `project.version` and this output (though doesn't seem to come through `slf4j`) also got turned off. – haridsv Jan 11 '16 at 07:07
  • The only answer that works without permanently messing with Maven installation. Another reason Maven is a dinosaur among the build system - it just doesn't have support for common sense requirements. – Abhijit Sarkar Aug 12 '17 at 20:34
23

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>
Greg Dubicki
  • 5,983
  • 3
  • 55
  • 68
Pawel Wrzeszcz
  • 255
  • 2
  • 2
14

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]
MD AFSAR ALI
  • 167
  • 1
  • 3
3

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.

btiernay
  • 7,873
  • 5
  • 42
  • 48
1

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

And beware: warn, not warning

Gangnus
  • 24,044
  • 16
  • 90
  • 149
1

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
confirmator
  • 374
  • 3
  • 11
1

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

  • 1
    This answer is OBSOLETE as of now - a) repo URL has changed, b) there is no INFO level statement in this code, c) diff URL doesn't work. – Greg Dubicki Mar 05 '15 at 09:39
  • Doesn't matter where the code uses INFO - when developing plugins, your mojo should rely on the maven logger with `getLog()` - if you can live with the configurability. – Adam Jul 25 '17 at 11:27
0

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

Hakan Özler
  • 968
  • 1
  • 10
  • 22
0

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
Sumith08
  • 582
  • 6
  • 16
  • Downvoted as this is a change of the source, whereas I believe the poster wanted a command line method, I certainly do! – Bill Naylor Mar 02 '21 at 18:13