Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flyway logs missing on the console when running commands #118

Open
lawrencej004 opened this issue Jan 6, 2025 · 0 comments
Open

Flyway logs missing on the console when running commands #118

lawrencej004 opened this issue Jan 6, 2025 · 0 comments

Comments

@lawrencej004
Copy link

Hello, it seems that in both the recent versions of the plugin v9.22.0 and v10.21.0 the logs from Flyway commands are missing in the console when running commands through SBT.
In Flyway v8 the LogFactory added a call to set the Flyway configuration on calls to Flyway.load() which in turn sets the logCreator to null.
This means that the SbtLogCreator is dropped as it is set before this point, and means that the logs to the SBT logger are missing from Flyway commands. If the logger is set after the call to load Flyway then this seems to fix the problem.

Example of before and after running the test1 test in the repo:

[info] Running flyway-sbt/test1
[info] [info] set current project to flyway-sbt-test1 (in build file:/private/var/folders/8t/f_6nqpkx0_q55_z0nrfcz8cw0000gn/T/sbt_3c9b75ad/)
[info] [info] welcome to sbt 1.5.8 (Amazon.com Inc. Java 17.0.13)
[info] [info] loading settings for project sbt_3c9b75ad-build from plugins.sbt ...
[info] [info] loading project definition from /private/var/folders/8t/f_6nqpkx0_q55_z0nrfcz8cw0000gn/T/sbt_3c9b75ad/project
[info] [info] loading settings for project sbt_3c9b75ad from build.sbt ...
[info] [info] set current project to flyway-sbt-test1 (in build file:/private/var/folders/8t/f_6nqpkx0_q55_z0nrfcz8cw0000gn/T/sbt_3c9b75ad/)
[info] [info] ans: String = null
[info] [success] Total time: 1 s, completed 6 Jan 2025, 16:51:05
[info] [success] Total time: 0 s, completed 6 Jan 2025, 16:51:06
[info] [info] +-----------+---------+----------------+------+---------------------+---------+----------+
[info] [info] | Category  | Version | Description    | Type | Installed On        | State   | Undoable |
[info] [info] +-----------+---------+----------------+------+---------------------+---------+----------+
[info] [info] | Versioned | 1       | First          | SQL  | 2025-01-06 16:51:06 | Success | No       |
[info] [info] | Versioned | 1.1     | Populate table | SQL  | 2025-01-06 16:51:06 | Success | No       |
[info] [info] +-----------+---------+----------------+------+---------------------+---------+----------+
[info] [success] Total time: 0 s, completed 6 Jan 2025, 16:51:06
[info] [info] ans: String = null
[info] [success] Total time: 0 s, completed 6 Jan 2025, 16:51:07
[info] [success] Total time: 0 s, completed 6 Jan 2025, 16:51:07
[info] [info] +-----------+---------+---------------------+------+---------------------+---------+----------+
[info] [info] | Category  | Version | Description         | Type | Installed On        | State   | Undoable |
[info] [info] +-----------+---------+---------------------+------+---------------------+---------+----------+
[info] [info] | Versioned | 1       | First               | SQL  | 2025-01-06 16:51:07 | Success | No       |
[info] [info] | Versioned | 1.1     | Populate test table | SQL  | 2025-01-06 16:51:07 | Success | No       |
[info] [info] +-----------+---------+---------------------+------+---------------------+---------+----------+
[info] [success] Total time: 0 s, completed 6 Jan 2025, 16:51:07
[info] + flyway-sbt/test1 

With the logger set after the call to load Flyway with missing logs in bold:

[info] Running flyway-sbt/test1
[info] [info] set current project to flyway-sbt-test1 (in build file:/private/var/folders/8t/f_6nqpkx0_q55_z0nrfcz8cw0000gn/T/sbt_2e0bbebd/)
[info] [info] ans: String = null
[info] [info] Flyway Community Edition 9.22.0 by Redgate
[info] [info] See release notes here: https://rd.gt/416ObMi
[info] [info] Database: jdbc:hsqldb:file:target/flyway_sample;shutdown=true (HSQL Database Engine 2.5)
[info] [info] Schema history table "PUBLIC"."flyway_schema_history" does not exist yet
[info] [info] Successfully dropped pre-schema database level objects (execution time 00:00.000s)
[info] [info] Successfully cleaned schema "PUBLIC" (execution time 00:00.001s)
[info] [info] Successfully cleaned schema "PUBLIC" (execution time 00:00.000s)
[info] [info] Successfully dropped post-schema database level objects (execution time 00:00.000s)
[info] [success] Total time: 1 s, completed 6 Jan 2025, 16:52:00
[info] [info] Database: jdbc:hsqldb:file:target/flyway_sample;shutdown=true (HSQL Database Engine 2.5)
[info] [info] Schema history table "PUBLIC"."flyway_schema_history" does not exist yet
[info] [info] Successfully validated 2 migrations (execution time 00:00.011s)
[info] [info] Creating Schema History table "PUBLIC"."flyway_schema_history" ...
[info] [info] Current version of schema "PUBLIC": << Empty Schema >>
[info] [info] Migrating schema "PUBLIC" to version "1 - First"
[info] [info] Migrating schema "PUBLIC" to version "1.1 - Populate table"
[info] [info] Successfully applied 2 migrations to schema "PUBLIC", now at version v1.1 (execution time 00:00.001s)
[info] [success] Total time: 0 s, completed 6 Jan 2025, 16:52:00
[info] [info] Database: jdbc:hsqldb:file:target/flyway_sample;shutdown=true (HSQL Database Engine 2.5)
[info] [info] +-----------+---------+----------------+------+---------------------+---------+----------+
[info] [info] | Category  | Version | Description    | Type | Installed On        | State   | Undoable |
[info] [info] +-----------+---------+----------------+------+---------------------+---------+----------+
[info] [info] | Versioned | 1       | First          | SQL  | 2025-01-06 16:52:00 | Success | No       |
[info] [info] | Versioned | 1.1     | Populate table | SQL  | 2025-01-06 16:52:00 | Success | No       |
[info] [info] +-----------+---------+----------------+------+---------------------+---------+----------+
[info] [success] Total time: 0 s, completed 6 Jan 2025, 16:52:01
[info] [info] ans: String = null
[info] [info] Database: jdbc:hsqldb:file:target/flyway_sample;shutdown=true (HSQL Database Engine 2.5)
[info] [info] Successfully dropped pre-schema database level objects (execution time 00:00.000s)
[info] [info] Successfully cleaned schema "PUBLIC" (execution time 00:00.001s)
[info] [info] Successfully cleaned schema "PUBLIC" (execution time 00:00.000s)
[info] [info] Successfully dropped post-schema database level objects (execution time 00:00.000s)
[info] [success] Total time: 0 s, completed 6 Jan 2025, 16:52:01
[info] [info] Database: jdbc:hsqldb:file:target/flyway_sample;shutdown=true (HSQL Database Engine 2.5)
[info] [info] Schema history table "PUBLIC"."flyway_schema_history" does not exist yet
[info] [info] Successfully validated 2 migrations (execution time 00:00.007s)
[info] [info] Creating Schema History table "PUBLIC"."flyway_schema_history" ...
[info] [info] Current version of schema "PUBLIC": << Empty Schema >>
[info] [info] Migrating schema "PUBLIC" to version "1 - First"
[info] [info] Migrating schema "PUBLIC" to version "1.1 - Populate test table"
[info] [info] Successfully applied 2 migrations to schema "PUBLIC", now at version v1.1 (execution time 00:00.001s)
[info] [success] Total time: 0 s, completed 6 Jan 2025, 16:52:02
[info] [info] Database: jdbc:hsqldb:file:target/flyway_sample;shutdown=true (HSQL Database Engine 2.5)
[info] [info] +-----------+---------+---------------------+------+---------------------+---------+----------+
[info] [info] | Category  | Version | Description         | Type | Installed On        | State   | Undoable |
[info] [info] +-----------+---------+---------------------+------+---------------------+---------+----------+
[info] [info] | Versioned | 1       | First               | SQL  | 2025-01-06 16:52:02 | Success | No       |
[info] [info] | Versioned | 1.1     | Populate test table | SQL  | 2025-01-06 16:52:02 | Success | No       |
[info] [info] +-----------+---------+---------------------+------+---------------------+---------+----------+
[info] [success] Total time: 0 s, completed 6 Jan 2025, 16:52:02
[info] + flyway-sbt/test1 

The changed code was on the configure function:

    def configure(config: Config): Flyway = {
      val flywayInstance = flyway
        .configure(config.base)
        .configure(config.migrationLoading)
        .configure(config.sqlMigration)
        .configure(config.migrate)
        .configure(config.placeholder)
        .configureSysProps(config.dataSource)
        .load()
      // Log creator needs to be set after calling Flyway.load() as it clears the log creator in the log factory
      LogFactory.setLogCreator(SbtLogCreator)
      flywayInstance
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant