How to log all generated SQL by Liquibase?

I’m finally able to see the SQL! :slight_smile: I needed to set the following system properties, the log setting in Spring Boot and create individual loggers.

-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
-Dlog4j2.disable.jmx=true
-Dliquibase.sql.logLevel=DEBUG
logging.level.liquibase=TRACE

Setting the LogManager is necessary because otherwise not all log messages are forwarded at all, the executor for example was missing. With a set LogManager I got some warning about JMX and therefore simply disabled it.

The log level for SQL needs to be set explicitly because the default of FINE doesn’t seem to be properly mapped into the JUL world. When I configure TRACE, liquibase.ui was partly logging warnings about TRACE not being supported and INFO will be used. But that’s the only warning I got within a lot of other log statements, while I assume TRACE not being supported at all for all other log statements as well. Not sure why liquibase.ui logged that instead of e.g. the executor…

WARNING: Unknown log level TRACE. Defaulting to ‘INFO’

Last but not least, all the loggers need to be defined explicitly in my case to individuall configure log levels. Having e.g. only the first line and the others commented, I still get all other log messages because of level TRACE in the Spring Boot config. That shouldn’t be the case in a proper parent-client naming relationship.

<Logger name="liquibase"                level="ERROR" />
<Logger name="liquibase.changelog"      level="INFO"  />
<Logger name="liquibase.command"        level="ERROR" />
<Logger name="liquibase.configuration"  level="ERROR" />
<Logger name="liquibase.database"       level="ERROR" />
<Logger name="liquibase.executor"       level="ERROR" />
<Logger name="liquibase.ext"            level="ERROR" />
<Logger name="liquibase.integration"    level="ERROR" />
<Logger name="liquibase.lockservice"    level="ERROR" />
<Logger name="liquibase.parser"         level="ERROR" />
<Logger name="liquibase.servicelocator" level="ERROR" />
<Logger name="liquibase.snapshot"       level="ERROR" />
<Logger name="liquibase.ui"             level="ERROR" />
<Logger name="liquibase.util"           level="ERROR" />
2024-01-22 DEBUG l.executor  : Changeset db/migration/[...].xml::[...]
2024-01-22 DEBUG l.executor  : CREATE TABLE "[...]".[...]
2024-01-22 DEBUG l.executor  : 0 row(s) affected
2024-01-22  INFO l.changelog : Table BRANCH created
2024-01-22  INFO l.changelog : ChangeSet db/migration/[...].xml::[...] ran successfully in 7029ms
2024-01-22 DEBUG l.executor  : INSERT INTO "[...]".DATABASECHANGELOG ("ID", AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('[...]', '[...]', 'db/migration/[...].xml', CURRENT TIMESTAMP, 2, '9:513f549e75cd3aacb010696f1ae9cd38', 'createTable tableName=BRANCH', '', 'EXECUTED', NULL, NULL, '4.25.1', '5946791675')
2024-01-22 DEBUG l.executor  : 1 row(s) affected
2024-01-22 DEBUG l.executor  : Changelog query completed.