Log levels for liquibase-core

My team has had no luck finding a way to set the logging level for the liquibase-core (4.24.0) library for Java. We are using it to stand up and tear down fixtures for our integration test suites but, as we do this before and after each test, our logs from these classes are now 99.9% liquibase INFO warnings that have no value for us.

Can we change the logging level for everything coming out of this dependency? I would hope there is a way to configure this via the Java Liquibase API as I’ve read that liquibase-core 4.. uses Java’s native logging utils instead of SLF4J as it used to?

There are 2 parameter to adjust the Liquibase logging level:

log-level: log-level

sql-log-level: sql-log-level

Those are fine when using the CLI or mvn but do not have a clear analogue that I can find in the Java API. How would we use those from the context of a Java class?

        final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
        final Path projectRoot = Paths.get(".").normalize().toAbsolutePath();
        final Map<String, Object> config = Map.of(
                Scope.Attr.database.name(), database,
                Scope.Attr.resourceAccessor.name(), new DirectoryResourceAccessor(projectRoot)
        );
        Scope.child(config, () -> {
            final CommandScope updateCommand = new CommandScope(UpdateCommandStep.COMMAND_NAME);
            updateCommand.addArgumentValue(DbUrlConnectionCommandStep.DATABASE_ARG, database);
            updateCommand.addArgumentValue(UpdateCommandStep.CHANGELOG_FILE_ARG, changelogFile);
            updateCommand.execute();
        });

Hi, I solved it for us after study Liquibase CLI source classes.
The way is configure “liquibase” logger

when logLevel is OFF

  void configureLogging(Level logLevel) throws IOException {
    this.logLevel = logLevel;
    HideSQLPreconditionFailedWarningFilter hideSQLPreconditionFailedWarningFilter = new HideSQLPreconditionFailedWarningFilter(); //own class that block log WARNING from failed precondition
    final LogService logService = Scope.getCurrentScope().get(Scope.Attr.logService, LogService.class);
    java.util.logging.Logger liquibaseLogger = java.util.logging.Logger.getLogger("liquibase");
    liquibaseLogger.setFilter(hideSQLPreconditionFailedWarningFilter);
    if (logService instanceof JavaLogService javaLogService) {
      javaLogService.setParent(liquibaseLogger);
    }

    System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT] %4$s [%2$s] %5$s%6$s%n");

    java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger("");
    rootLogger.setFilter(hideSQLPreconditionFailedWarningFilter);
    List<String> channels = new ArrayList<>(Arrays.asList("", "liquibase"));
    for (String channel : channels) {
      Logger logger = java.util.logging.Logger.getLogger(channel);
      logger.setLevel(logLevel);
      logger.setFilter(hideSQLPreconditionFailedWarningFilter);
    }
    for (Handler handler : rootLogger.getHandlers()) {
      if (handler instanceof ConsoleHandler) {
        handler.setLevel(logLevel);
        handler.setFilter(hideSQLPreconditionFailedWarningFilter); //from debug only here was filter present nd true
      }
      JavaLogService.setFormatterOnHandler(logService, handler);
    }
  }

It isn’t nice and probably could be simplified. I don’t want spent more time on this as we use it only in one of our workflow build tool.

and maybe this could help too: java.util.logging: Programmatic configuration and logging with Java8 lambdas