我有一個配置爲使用SLF4J + Logback的小應用程序。我從Flyway獲取JUL輸出,我希望Logback能夠處理這些輸出。Flyway Logback的日誌記錄
FlywayWrapper.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FlywayWrapper {
private static final Logger logger = LoggerFactory.getLogger(FlywayWrapper.class);
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{ISO8601} [%thread] %-5level %logger{0}: %msg%n</pattern>
</encoder>
</appender>
<logger name="com.foo.test" level="INFO" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
而且我看到控制檯日誌記錄,像這樣:
2014-09-01 12:53:47,405 [main] INFO FlywayWrapper: Operation >> migrate
Sep 01, 2014 12:53:47 PM org.flywaydb.core.internal.dbsupport.DbSupportFactory createDbSupport
INFO: Database: jdbc:postgresql://localhost:5433/test (PostgreSQL 9.2)
Sep 01, 2014 12:53:47 PM org.flywaydb.core.internal.command.DbValidate validate
INFO: Validated 3 migrations (execution time 00:00.055s)
我在org.flywaydb.core.internal.util.logging.LogFactory
注意到這這可能是爲什麼JUL是正在使用。
public static Log getLog(Class<?> clazz) {
if (logCreator == null) {
FeatureDetector featureDetector = new FeatureDetector(Thread.currentThread().getContextClassLoader());
if (featureDetector.isAndroidAvailable()) {
logCreator = new AndroidLogCreator();
} else if (featureDetector.isApacheCommonsLoggingAvailable()) {
logCreator = new ApacheCommonsLogCreator();
} else {
logCreator = new JavaUtilLogCreator();
}
}
return logCreator.createLogger(clazz);
}
有關我如何讓Flyway使用我的日誌記錄後端的任何想法?