Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 2993

Unable to replace logger, ServiceLocator.instance() returns null

$
0
0
Java SDK 1.8.0_131
Liquibase 3.5.3
eclipse IDE Neon 3 (eclipse 4.6.3)

I am trying to replace the logger as outlined in Fixing liquibase logging (in Spring) with SLF4J and Log4J but so far I haven't been successful.  

The reason seems to be because ServiceLocator.instance(), called from LogFactory.getLog(), returns a null, and the defaultLogger is returned instead.

Is there some obvious initialization code that may I have missed? (I have used examples found by googling, combined with trial and error).

I first tried replacing the logger by adding a maven dependency to Matt Bertolinis liquibase-slf4j, but that didn't have any effect.

I then tried replacing the logger as simply as possible:
  1. Created a package liquibase.ext.logging in the project where I'm calling Liquibase from
  2. Created a class "public class UkelonnLiquibaseLogger extends AbstractLogger" in this package
The UkelonnLiquibaseLogger class at this time, just had empty methods.  I figured that if all of the Liquibase output went away, the class would have been found, and that I would see this as soon as I started running unit tests.

But the liquibase output continued to be written to the console, so the class wasn't picked up.

When I debugged into the startup code I was able to hit code in the ServiceLocator constructor, called from the static initializer of the ServiceLocator class. Eclipse didn't let me set any breakpoints inside the static initializer of ServiceLocator so I wasn't able to see what was going on there. I wasn't able to figure out if any exceptions were thrown from the constructor either.

However when I next hit the breakpoints in ServiceLocator.getInstance() the instance was null.

I had a breakpoint in ServiceLocator.setInstance() as well, but this breakpoint was never called.

This is how I create and use Liquibase:
  1.     public void createSchema(PooledConnection connect) throws SQLException, LiquibaseException {
  2.         DatabaseConnection databaseConnection = new JdbcConnection(connect.getConnection());
  3.         ClassLoaderResourceAccessor classLoaderResourceAccessor = new ClassLoaderResourceAccessor(getClass().getClassLoader());
  4.         Liquibase liquibase = new Liquibase("db-changelog/db-changelog.xml", classLoaderResourceAccessor, databaseConnection);
  5.         liquibase.update("");
  6.     }
Thanks!

- Steinar

Viewing all articles
Browse latest Browse all 2993

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>