Liquibase standalone --log-level=INFO duplicates logs

I’m running liquibase as initContainer for my service.

      initContainers:
        - name: liquibase
          image: docker.io/liquibase/liquibase:4.27.0
          command:
            - "liquibase"
            - "update"
            - "--changeLogFile=db/changelog/db.changelog-root.xml"
            - "--url=$(LIQUIBASE_COMMAND_URL)"
            - "--username=$(LIQUIBASE_COMMAND_USERNAME)"
            - "--password=$(LIQUIBASE_COMMAND_PASSWORD)"
            - "--log-level=INFO"

I’ve noticed that setting the log level to INFO causes the log statements to be “duplicated”.

Liquibase Version: 4.27.0
[2024-10-25 08:46:57] INFO [liquibase.ui] Liquibase Version: 4.27.0
Liquibase Open Source 4.27.0 by Liquibase
[2024-10-25 08:46:57] INFO [liquibase.ui] Liquibase Open Source 4.27.0 by Liquibase

My assumption is that there’s multiple loggers or appenders or something like an issue with additivity. I’ve checked the Liquibase docs but I didn’t manage to find anything related to the issue.

Is there any way to prevent the log statements from showing up twice but still have INFO log level?

The issue you’re encountering with Liquibase logging statements appearing to be duplicated is likely due to multiple logging frameworks or appenders being used within the logging configuration. Here’s how to troubleshoot and potentially resolve this problem while still maintaining the INFO log level.

Steps to Resolve Duplicate Logging in Liquibase

  1. Check Logging Configuration: Liquibase uses SLF4J for logging, which can work with different backends such as Logback, Log4j, or JDK logging. Ensure that you have a single logging framework configured to avoid duplication.
  2. Using Logback: If you’re using Logback, check the logback.xml configuration. Look for the root logger and appenders, and ensure that there aren’t multiple appenders logging to the same output:
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level [%logger{36}] %msg%n</pattern>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>

Ensure that the root logger does not reference the same appender multiple times or any other appenders that may be duplicating the output.
3. Review SLF4J Bindings: Ensure that only one SLF4J binding is included in your classpath. If there are multiple bindings (e.g., slf4j-log4j12, slf4j-logback), it can lead to unexpected behavior. You can check your dependencies in your Dockerfile or Kubernetes setup and ensure that there’s only one binding present.
4. Use Custom Logging Levels: If you cannot find any duplicates, consider setting up a custom logging configuration specifically for Liquibase. This can be done through your logging framework’s configuration file. You can define specific loggers for the Liquibase package to control its output independently.Example for Logback:

<logger name="liquibase" level="INFO">
    <appender-ref ref="STDOUT"/>
</logger>
  1. Check for Default Configuration: If you are running Liquibase in an environment where it might have a default logging configuration (like in some managed services), it could potentially interfere with your settings. Ensure that your configuration is taking precedence.
  2. Run with Debug Logs: Temporarily set the log level to DEBUG to see if additional logs provide insight into where the duplication is happening.
- "--log-level=DEBUG"

Example Configurations

Here’s a minimal example using Logback for the Liquibase container:

logback.xml:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level [%logger{36}] %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="liquibase" level="INFO">
        <appender-ref ref="STDOUT"/>
    </logger>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>

Summary

By ensuring that there is no duplication in your logging framework configuration and by specifying loggers and appenders appropriately, you should be able to resolve the issue of duplicate log messages while keeping the logging level at INFO. If the issue persists, you may want to consider updating the Liquibase version, as bugs can sometimes be resolved in newer releases.