Maven Log binding for SLF4J
Maven Log to SLF4J binding is implemented with StaticLoggerBinder
singleton. This is how you use it in your Maven plugin:
import com.jcabi.log.Logger; import org.apache.maven.plugin.AbstractMojo; import org.slf4j.impl.StaticLoggerBinder; public class MyMojo extends AbstractMojo { @Override public void execute() { StaticLoggerBinder.getSingleton().setMavenLog(this.getLog()); // ... later ... Logger.info(this, "hello, world!"); // and you can still use the usual logging mechanism this.getLog().info("hello again"); } }
The Logger.info()
call will go to Maven Log through SLF4J.
Since 0.7.12 log stream is forwarded to SystemStreamLog
if StaticLoggerBinder.setMavenLog()
is not called. In earlier versions a runtime exception was thrown.
The only dependency you need (you can also download jcabi-maven-slf4j-0.12.2.jar
and add it to the classpath):
<dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-maven-slf4j</artifactId> <version>0.12.2</version> </dependency>
Cutting Edge Version
If you want to use current version of the product, you can do it with this configuration in your pom.xml
:
<repositories> <repository> <id>oss.sonatype.org</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-maven-slf4j</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies>