Maven 3.1.x logging

Maven 2.x and 3.0.x use 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. 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 simplelogger.properties, slf4j-api-x.y.z-jar and slf4j-simple-x.y.z.jar specifically relate to the SLF4J implementation:

m2
├── LICENSE.txt
├── NOTICE.txt
├── README.txt
├── bin
│   └── ...
├── boot
│   └── ...
├── conf
│   ├── logging
│   │   └── simplelogger.properties
│   └── settings.xml
└── lib
    ├── ...
    ├── slf4j-api-x.y.z.jar
    ├── slf4j-simple-x.y.z.jar
    └── ...

Configuring logging

To configure logging with the SLF4J Simple, you can edit the properties in the ${MAVEN_HOME}/conf/logging/simplelogger.properties file. The following table lists the available configuration properties along with the SLF4J Simple defaults.

org.slf4j.simpleLogger.logFile The output target which can be the path to a file, or the special values "System.out" and "System.err". Default is "System.err".
org.slf4j.simpleLogger.defaultLogLevel Default log level for all instances of SimpleLogger. Must be one of ("trace", "debug", "info", "warn", or "error"). If not specified, defaults to "info".
org.slf4j.simpleLogger.log.a.b.c Logging detail level for a SimpleLogger instance named "a.b.c". Right-side value must be one of "trace", "debug", "info", "warn", or "error". When a SimpleLogger named "a.b.c" is initialized, its level is assigned from this property. If unspecified, the level of nearest parent logger will be used, and if none is set, then the value specified by org.slf4j.simpleLogger.defaultLogLevel will be used.
org.slf4j.simpleLogger.showDateTime Set to true if you want the current date and time to be included in output messages. Default is true
org.slf4j.simpleLogger.dateTimeFormat The date and time format to be used in the output messages. The pattern describing the date and time format is defined by SimpleDateFormat. If the format is not specified or is invalid, the number of milliseconds since start up will be output.
org.slf4j.simpleLogger.showThreadName Set to true if you want to output the current thread name. Defaults to true.
org.slf4j.simpleLogger.showLogName Set to true if you want the Logger instance name to be included in output messages. Defaults to true.
org.slf4j.simpleLogger.showShortLogName Set to true if you want the last component of the name to be included in output messages. Defaults to false.
org.slf4j.simpleLogger.levelInBrackets Should the level string be output in brackets? Defaults to false.
org.slf4j.simpleLogger.warnLevelString The string value output for the warn level. Defaults to WARN.

Every entry in this file can be overriden via commandline arguments by passing it with the -D flag. E.g. -Dorg.slf4j.simpleLogger.showThreadName=true will add the thread name to every logging line.

The default configuration for Maven looks like the following:

# Default Maven logging configuration
#
org.slf4j.simpleLogger.defaultLogLevel=info
org.slf4j.simpleLogger.showDateTime=false
org.slf4j.simpleLogger.showThreadName=false
org.slf4j.simpleLogger.showLogName=false
org.slf4j.simpleLogger.logFile=System.out
org.slf4j.simpleLogger.levelInBrackets=true
org.slf4j.simpleLogger.log.Sisu=info
org.slf4j.simpleLogger.warnLevelString=WARNING

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”.