A lot of people are unsure how to fix logging for liquibase, either to the console or file.
Is it possible to make liquibase log to slf4j?
A lot of people are unsure how to fix logging for liquibase, either to the console or file.
Is it possible to make liquibase log to slf4j?
Here is my recipe to make liquibase 3.5.3 log into file under windows when running from command line. It doesn't use exactly 'slf4j' but solves the problem of getting log files of db updates, by making liquibase use java.util.logging.
1) get the liquibase-javalogger-3.0.jar from here https://github.com/liquibase/liquibase-javalogger/releases/
2) put it to %LIQUIBASE_HOME%/lib directory
3) create logger.properties file with the following content:
handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
.level=FINEST
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.pattern=liquibase.log
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.append=true
#2018-04-28 17:29:44 INFO Example logging record
java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %5$s%6$s%n
4) add java option to liquibase (for example via set JAVA_OPTS=...):
-Djava.util.logging.config.file=logger.properties
Example of my liquibase wrapper batch file :
set username=%USER%
set password="%PASSWORD%"
set URL="jdbc:db2://mydbserver:50000/MYDB"
set JAVA_OPTS=-Djava.util.logging.config.file=db2/logger.properties
call liquibase.bat ^
--driver="com.ibm.db2.jcc.DB2Driver" ^
--defaultSchemaName=MYSCHEMA ^
--liquibaseSchemaName=MYSCHEMA ^
--changeLogFile=db2/changelog.xml ^
--url=%URL% ^
--username=%USER% ^
--password="%PASSWORD%" ^
--logLevel=debug
UPDATE:
I've switched to new liquibase version which is using logback by default. For liquibase 3.6.2 use the following setup to run from windows command line:
1) Ensure slfj is reachable in java classpath. Put the slf4j-api-1.7.25.jar in liquibase/lib folder. The jar file can be found in the official slfj distribution package: https://www.slf4j.org/download.html
2) Set logback configuration file path parameter:
JAVA_OPTS=-Dlogback.configurationFile=logback.xml
3) Add logback.xml configuration file. Example is here: https://www.mkyong.com/logging/logback-xml-example/