How do I hook custom logger?

Hi there! Somewhat new to Liquibase, enjoying it, and not sure I’ve got my logger plugged the right way.

What is the preferred or correct way to hook in my custom logger?

What I share below has been successful, but I also see from an '09 post there was/is a provision for placing the logger so it will automatically be picked up.

Scope.child(Scope.Attr.logService.name(), new LiquibaseLogger(), () -> {
     // stuff here, but basically just calling Liquibase.update(...)
}

Also, LiquibaseLogger has this setup:

LiquibaseLogger extends AbstractLogService implements Logger

Perhaps there is another way too? Any help is much appreciated. Thanks!

Hi @daver,

Are you looking for something like mentioned on this SO post?

This explains the use of log4j with liquibase to enable custom logging mechanism.

Thanks!
Rakhi Agrawal

Thank you rakhi! I was able to use the information you provided as well as review the structure of the JavaLogger to see how to plug in my custom logger extension that uses SLF4J with JUL to log to the console and a file.

In a nutshell, it went like this:

  1. Create a class with type:
    public class LiquibaseLogger extends AbstractLogService implements Logger

    Be sure to set priority to a number that will permit logging. I chose ‘5’ as did Bertolini since he seemed to know what he was doing (and that worked for me).

  2. Create the following file with given contents in location:
    Location: resources/META-INF/services
    File Name: liquibase.logging.LogService
    File Contents: liquibase.ext.logging.LiquibaseLogger

Breakpoints were hit as well as logging happened as expected.

That’s great, @daver

Thanks for providing the details on this post. It will surely help others looking for implementing custom logging anytime in future.

Thanks,
Rakhi Agrawal

1 Like