问题
I'm writing a Maven 3.x plugin and want to log with SLF4J & Logback.
I found some SLF4J bindings for the Maven Logger:
- http://www.jcabi.com/jcabi-maven-slf4j/index.html
- https://bitbucket.org/peachjean/slf4j-mojo
However, these seem to be SLF4J bindings but I believe what I need is a bridge for the Maven Logger i.e. to bridge/route all Maven log statements to SLF4J and use LogBack binding with logback.xml config.
回答1:
You can use SLF4J directly from Maven plugin since Maven 3.1:
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.
No bridges, bindings, etc. needed.
Source: https://maven.apache.org/maven-logging.html
回答2:
Your plugin should log through Log class. Logback is not required. Just forward all your logs to SLF4J and add jcabi-maven-slf4j dependency to the plugin. That's it.
来源:https://stackoverflow.com/questions/22271518/slfj4-bridge-for-the-maven-logger