使用Logback进行Flyway日志记录 [英] Flyway logging with Logback

查看:384
本文介绍了使用Logback进行Flyway日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个配置为使用SLF4J + Logback的小型应用程序.我正在从Flyway获取JUL输出,我希望Logback可以处理.

I have a small application configured to use SLF4J + Logback. I'm getting JUL output from Flyway which I'd like Logback to handle.

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>

我看到控制台记录如下:

And I'm seeing console logging like so:

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的原因.

I've noticed this in org.flywaydb.core.internal.util.logging.LogFactory which is probably why JUL is being used.

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使用我的日志记录后端的任何想法?

Any ideas on how I can get Flyway to use my logging backend?

推荐答案

这将在3.1版本中得到支持: https://github.com/flyway/flyway/issues/834

This will be supported as part of the 3.1 release: https://github.com/flyway/flyway/issues/834

这篇关于使用Logback进行Flyway日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆