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

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

$
0
0
Now I've succeeded in having the custom logger picked up when running in the unit tests.

What I did to fix this, was to ensure that the getPriority() method of my logger returned a high number:
  1. package liquibase.ext.logging;

  2. import liquibase.logging.core.AbstractLogger;

  3. public class UkelonnLiquibaseLogger extends AbstractLogger {
  4.     ...
  5.     /**
  6.      * The value returned here will determine if liquibase is to use this logger.
  7.      * If the value is too low, liquibase will use the default logger.
  8.      */
  9.     @Override
  10.     public int getPriority() {
  11.         return Integer.MAX_VALUE;
  12.     }
  13. }
When debugging I found that the ServiceLocator.getInstance() method eventually returned something other than null, and a logger was attempted created. However, since the getPriority() method returned 0, the default logger was picked instead.

Now this works for me in the unit tests.

However, in the OSGi context liquibase still logs to the console. This happens both in the karaf-based pax exam tests, and in apache karaf itself.

I have exported the liquibase.ext.logger package from the OSGi bundle the UkelonnLiquibaseLogger is implemented in.

FYI The reason I picked ClassLoaderResourceAccessor over the OSGiResourceAccessor, was that I couldn't figure out how to make the OSGiResourceAccessor work in the unit tests, and the ClassLoaderResourceAccessor with the class loader set explicitly, finds the database changeset files both when running in unit tests and when running in OSGi.

Viewing all articles
Browse latest Browse all 2993

Trending Articles