# Log levels for liquibase-core

**URL:** <https://forum.liquibase.org/t/log-levels-for-liquibase-core/8746>\
**Category:** General Discussion\
**Created:** [October 20, 2023, 4:01pm UTC](https://forum.liquibase.org/t/log-levels-for-liquibase-core/8746 "2023-10-20T16:01:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tengel](https://avatars.discourse-cdn.com/v4/letter/t/edb3f5/32.png) [@tengel](https://forum.liquibase.org/u/tengel)\
**Post date:** [October 20, 2023, 4:01pm UTC](https://forum.liquibase.org/t/log-levels-for-liquibase-core/8746/1 "2023-10-20T16:01:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![daryldoak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/daryldoak/32/764_2.png) [@daryldoak](https://forum.liquibase.org/u/daryldoak)\
**Post date:** [October 20, 2023, 4:49pm UTC](https://forum.liquibase.org/t/log-levels-for-liquibase-core/8746/2 "2023-10-20T16:49:41Z")

</div>

There are 2 parameter to adjust the Liquibase logging level:

log-level: [log-level](https://docs.liquibase.com/parameters/log-level.html)

sql-log-level: [sql-log-level](https://docs.liquibase.com/parameters/sql-log-level.html)

---

<div class="post-metadata">

**Author:** ![tengel](https://avatars.discourse-cdn.com/v4/letter/t/edb3f5/32.png) [@tengel](https://forum.liquibase.org/u/tengel)\
**Post date:** [October 20, 2023, 7:20pm UTC](https://forum.liquibase.org/t/log-levels-for-liquibase-core/8746/3 "2023-10-20T19:20:28Z")

</div>

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?

```auto
        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();
        });

```

---

<div class="post-metadata">

**Author:** ![Lumir](https://avatars.discourse-cdn.com/v4/letter/l/aeb1de/32.png) [@Lumir](https://forum.liquibase.org/u/Lumir)\
**Post date:** [December 12, 2023, 7:58am UTC](https://forum.liquibase.org/t/log-levels-for-liquibase-core/8746/4 "2023-12-12T07:58:45Z")

</div>

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

when logLevel is OFF

```auto
  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](https://nozaki.me/roller/kyle/entry/java-util-logging-programmatic-configuration)
