Maven 3.1.x logging

Maven uses Plexus logging API with basic Maven implementation writing to stdout.

We have reached the decision that SLF4J is the best option for a logging API: SLF4J has reached a certain level of ubiquity and while SLF4J may not be perfect, it's the de facto standard and it's pointless to try and remake another one. There are many implementations to choose from, including Logback and Log4j2. All the hard work has been done. All the bridges and funnels for other systems function well, which allows others to use whatever logging implementation they like in their components, while still being able to have integrated logging.

The standard Maven distribution, from Maven 3.1.0 onward, uses the SLF4J API for logging combined with the SLF4J Simple implementation (or a customized version since 3.5.0). Future versions may use a more advanced implementation, but we chose to start simple.

Looking at the distribution you will see the following layout where the, slf4j-api-x.y.z-jar and slf4j-simple-x.y.z.jar (or maven-slf4j-provider-3.x.y.jar since 3.5.0) specifically relate to the SLF4J implementation:

├── LICENSE.txt
├── NOTICE.txt
├── README.txt
├── bin
│   └── ...
├── boot
│   └── ...
├── conf
│   ├── logging
│   │   └──
│   └── settings.xml
└── lib
    ├── ...
    ├── slf4j-api-x.y.z.jar
    ├── slf4j-simple-x.y.z.jar or maven-slf4j-provider-3.x.y.jar
    └── ...

Configuring logging

To configure logging with the SLF4J Simple, you can edit the properties in the ${maven.home}/conf/logging/ file. Please see the linked reference documentation for details.

Every entry in this file can be overridden via Maven's JVM system properties by using the -D flag in MAVEN_OPTS, for example:

  • MAVEN_OPTS=-Dorg.slf4j.simpleLogger.showThreadName=true mvn <goals> will add the thread name to every logging line,
  • MAVEN_OPTS=-Dorg.slf4j.simpleLogger.showLogName=true mvn <goals> will add the logger name to every logging line,

The default SLF4J configuration for Maven is listed here, where you can see other useful property names to customise logging.

Changing the SLF4J implementation

If you want use a different logging implementation it is simply a matter of removing the slf4j-simple JAR from the lib directory and replacing it with one of the alternative implementations, like Log4j2 or Logback.

See SLF4J documentation for more details on swapping “SLF4J bindings”.

Note: with the introduction of colors in Maven 3.5.0, perhaps an equivalent work to maven-slf4j-provider may be required or you'll loose colors.

Maven implemenation details

More technical details can be found in Maven release reference documentation.