如何为Flyway命令行配置日志记录 [英] How configure logging for Flyway command line

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

问题描述

在我的工作中,我们开始使用flyway,数据库管理员问我flyway是否有日志.在阅读了一些有关Internet和有关Flyway文档的文章之后,我没有找到进行此配置的方法.

Here on my job we started the use of flyway and the databases admins asked to me if the flyway has a log. After read some articles on internet and on documentation of the flyway, I did not find a way to do this configuration.

在StackOverflow上,一些用户说只需要将log4j放在类路径上就可以了.我尝试放置log4j文件,但对我不起作用,但是当我尝试将SLF4J文件放置在flyway的lib目录(类路径)中时:

Here on StackOverflow some users say that only is necessary put the log4j on classpath and it should work. I tried put log4j files but does not work for me, however when I tried put the files of SLF4J on lib directory of flyway (classpath):

  • slf4j-api-1.7.21.jar
  • slf4j-simple-1.7.21.jar
  • simplelogger.properties.

flyway的输出已更改,插入了日志记录前缀:

The output of flyway has changed inserting logging prefixes:

C:\ dev \ flyway-4.0.3> flyway -configFile = C:/dev/repos \ flyway/ad/DT/flyway.conf/flyway.conf信息-q [main] INFO org.flywaydb.core.internal.util.VersionPrinter-Boxfuse的Flyway 4.0.3 [main] INFO org.flywaydb.commandline.Main- [main] INFO org.flywaydb.core.internal.dbsupport.DbSupportFactory-数据库:jdbc:sqlserver://xxxxxxxxxx \ sql2008:1437; authentication = NotSpecified; authenticationScheme = nativeAuthentication; xopenStat es = false; sendTimeAsDatetime = true; trustServerCertificate = false; TransparentNetworkIPResolution = true; serverNameAsACE = false; sendStringParametersAsUnicode = true; selectMethod = direct; responseBuffering = adaptiv e; packetSize = 8000; multiSubnetFailover = false; loginTimeout = 15; lockTimeout = -1; lastUpdateCount = true; encrypt = false; disableStatementPooling = true; databaseName = TST_FLYWAY; columnEncryptionSetting = Disabled; appl icationName =用于SQL Server的Microsoft JDBC驱动程序; applicationIntent =可读写; (Microsoft SQL Server 10.50) [main] INFO org.flywaydb.core.internal.dbsupport.sqlserver.SQLServerDbSupport-SQLServer不支持为当前会话设置架构.默认架构未更改为[flyway] [main] INFO org.flywaydb.commandline.Main-

C:\dev\flyway-4.0.3>flyway -configFile=C:/dev/repos\flyway/ad/DT/flyway.conf/flyway.conf info -q [main] INFO org.flywaydb.core.internal.util.VersionPrinter - Flyway 4.0.3 by Boxfuse [main] INFO org.flywaydb.commandline.Main - [main] INFO org.flywaydb.core.internal.dbsupport.DbSupportFactory - Database: jdbc:sqlserver://xxxxxxxxxx\sql2008:1437;authentication=NotSpecified;authenticationScheme=nativeAuthentication;xopenStat es=false;sendTimeAsDatetime=true;trustServerCertificate=false;TransparentNetworkIPResolution=true;serverNameAsACE=false;sendStringParametersAsUnicode=true;selectMethod=direct;responseBuffering=adaptiv e;packetSize=8000;multiSubnetFailover=false;loginTimeout=15;lockTimeout=-1;lastUpdateCount=true;encrypt=false;disableStatementPooling=true;databaseName=TST_FLYWAY;columnEncryptionSetting=Disabled;appl icationName=Microsoft JDBC Driver for SQL Server;applicationIntent=readwrite; (Microsoft SQL Server 10.50) [main] INFO org.flywaydb.core.internal.dbsupport.sqlserver.SQLServerDbSupport - SQLServer does not support setting the schema for the current session. Default schema NOT changed to [flyway] [main] INFO org.flywaydb.commandline.Main -

但是在 simplelogger.properties 文件上配置的目录上没有创建文件:

But no file was created on the directory that I configured on simplelogger.properties file:

org.slf4j.simpleLogger.logFile = C:/dev/flyway-4.0.3/log/flyway.log

org.slf4j.simpleLogger.logFile=C:/dev/flyway-4.0.3/log/flyway.log

我应该如何配置日志?

任何帮助都将受到欢迎.

Any help will be welcome.

推荐答案

使用slf4j并重新登录 在何处添加文件(也可以使用simplelogger,但登录更好)

Using slf4j and logback where to add the file (you can use simplelogger also but logback is better)

  C: \ flyway - 4.0.3
 ├─ conf
 │ logback.xml
 └ ─ lib
        Logback-classic-1.1.7.jar
        Logback-core-1.1.7.jar
        Slf4j-api-1.7.21.jar 

Logback.xml

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <property scope="context" name="LOG_DIR" value="logs" />

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p : %m%n</pattern>
        </encoder>
    </appender>
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_DIR}/flyway.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_DIR}/flyway.%d{yyyy-MM-dd}.log</fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p : %m%n</pattern>
        </encoder>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE" />
    </root>

</configuration>

修改flyway.cmd

%JAVA_CMD% -cp "%INSTALLDIR%\conf;%INSTALLDIR%\lib\*;%INSTALLDIR%\drivers\*" org.flywaydb.commandline.Main %*

这篇关于如何为Flyway命令行配置日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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