Maven Logging
End-user logging documentation is available in Maven site. This documentation is focused on internal implementation details.
Logging API
Maven uses Plexus Container logging API, like any other Plexus components, ie LoggerManager / Logger.
Starting with Maven 3.1.0:
- Maven supports SLF4J API logging API too, ie LoggerFactory / Logger,
- instead of implementing Plexus logging API itself with basic output to console, Maven implements it using SLF4J API in Slf4jLoggerManager / Slf4jLogger.
Logging Implementation
Maven 3.1.0 ships bundled with SLF4J simple logger, but is ready to use other logging implementations: SLF4J is responsible for loading the implementation, referred to as "SLF4J bindings".
Logging configuration loading is actually done by logging implementation, without any Maven extensions to support merging Maven installation configuration with per-user configuration for example: ${maven.conf}/logging
directory was added to core's classpath (see ${maven.home}/bin/m2.conf
). See your implementation documentation for details on file names, formats, and so on.
During Maven initialization, Maven tweaks default root logging level to match CLI verbosity choice. Since such feature isn't available in SLF4J API, logging implementation specific extensions need to be added into Maven to support these CLI options: see Slf4jConfigurationFactory / Slf4jConfiguration.
Getting Logger Instance
Starting with Maven 3.1.0, SLF4J Logger can be used directly. This technique can be used safely in Maven core components or in plugins/component not requiring compatibility with previous Maven versions.
import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MyClass { final Logger logger = LoggerFactory.getLogger( MyClass.class ); }
Logger Name
Before Maven 3.1.0, with logging implementation done in Maven, logger name wasn't used by basic console logging implementation: they are as-is, without clear convention on when to pass logger from class to class or when to create a new logger.
Starting with Maven 3.1.0, logging implementation can be of greatest use if logger names are well defined. This definition still needs to be defined and implemented:
- classical "class name" pattern?
- Maven-specific name hierarchy?
- a mix (some with class name, some with Maven-specific hierarchy)?