Giter VIP home page Giter VIP logo

liquibase-slf4j's Introduction

liquibase-slf4j

Version 5.0.0
Written by Matt Bertolini

Maven Central javadoc Build Status

An implementation of the Liquibase logger that delegates directly to SLF4J.

Liquibase has a logging mechanism that delegates to java.util.logging. It works great with SLF4J out of the box if you use jul-to-slf4j library. Unfortunately, there is a known performance impact when bridging java.util.logging to SLF4J. This library helps to eliminate that performance impact by logging Liquibase directly to SLF4J.

How to Use

Grab the library from Maven Central and place it in your classpath.

Maven:

<dependency>
    <groupId>com.mattbertolini</groupId>
    <artifactId>liquibase-slf4j</artifactId>
    <version>5.0.0</version>
    <scope>runtime</scope>
</dependency>

Gradle:

Groovy DSL:

runtimeOnly 'com.mattbertolini:liquibase-slf4j:5.0.0'

Kotlin DSL:

runtimeOnly("com.mattbertolini:liquibase-slf4j:5.0.0")

Ivy

<dependency org="com.mattbertolini" name="liquibase-slf4j" rev="5.0.0"/>

License

liquibase-slf4j is licensed under the MIT License

Notes

This logger has a priority number of 5. If there is more than one Liquibase logger on the classpath the one with the highest priority will be used. The priority number can be changed by setting the system property com.mattbertolini.liquibase.logging.slf4j.Slf4jLogService.priority to an integer value of your choice.

Version 4 of Liquibase introduced a new plugin loading mechanism based on the Java ServiceLoader. Version 3.0.0 of this logger conforms to this new loader mechanism. If you are using Liquibase versions lower than 4, continue to use version 2.0.0 of this library.

Liquibase version 3.4.0 had an issue loading third party loggers in some situations. This logger may not work on that version. It is recommended to upgrade to Liquibase 3.4.1 which addresses this issue.

Log Level Mappings

Liquibase Level SLF4J Level
Debug (Deprecated) Debug
Fine Debug
Config Info
Info Info
Warning Warn
Severe Error

Build and Test

Requirements

  • Apache Ant - Version 1.10.6 or higher.
  • JDK 11 or higher (Compiled with 1.8 source and target).

Build

To build this project, clone the repo and run the ant command:

git clone https://github.com/mattbertolini/liquibase-slf4j.git
cd liquibase-slf4j
ant

The distributable jar files will be located in the dist folder. The build reports (unit test, coverage, etc.) will be located in the build/reports dir.

To list all available tasks:

ant -p

Bugs

Please report any bugs in the issue tracker above. Please be as detailed as possible in the report, so I can create unit tests to verify the problem is fixed.

Release Notes

5.0.0 - 2023-03-20

  • Add JPMS module-info file to support Java 9+ modules.
  • Build now requires Java 11 or higher. The source is still compiled to Java 8 bytecode.
  • Upgraded to SLF4J 2.x (2.0.7)
  • Upgrade to Liquibase 4.19.0
  • Remove deprecated logging filter support.
  • Switched from TravisCI to GitHub Actions.

4.1.0 - 2022-03-30

  • Generated OSGi metadata making the jar a OSGi fragment where Liquibase is the host bundle. This was tested with Liquibase 4.9.1. This fixes issue #12 (Pull Request)
  • Upgraded to SLF4J 1.7.36
  • Upgraded to Liquibase 4.9.1. The library should still work with Liquibase 4.1.0 and above when not using OSGi.

4.0.0 - 2020-09-30

  • Upgraded Liquibase to version 4.1.0. This is a breaking change as the logging API introduced a new filter class and changed constructors. (Pull Request)

3.0.0 - 2020-07-23

  • Upgraded to Liquibase version 4.0.0. This is a breaking change as the logging API changed significantly. Use version 2.x if you are using Liquibase versions lower than 4.0.0.
  • Upgraded to SLF4J 1.7.30.
  • Added the ability to change the priority number of the logger by setting a Java property. To change the priority, set the com.mattbertolini.liquibase.logging.slf4j.Slf4jLogService.priority property to an integer value.
  • Repackaged logger now that package name is no longer used for locating third-party loggers.
  • Java 8 is now the minimum supported JDK version.
  • Added an Automatic-Module-Name to support the Java 9+ module system. The module name is com.mattbertolini.liquibase.logging.slf4j.
  • Overhauled build files.

2.0.0 - 2015-12-16

  • Switched the dependency scope of SLF4J and Liquibase to provided. This is because most users are already including their own versions of these libraries and the versions are often much newer than what is defined in this library. By marking them as provided it helps prevent version conflicts and extra exclusions in project files. For an example of this, check out the POM file from Dropwizard
  • The minimum required Liquibase version is now 3.2.0. This is done to take advantage of updates to AbstractLogger.

1.2.1 - 2013-10-12

  • Only printing the changeLogName and changeSetName if they are provided. This gets rid of the annoying nulls printed in logs.

1.2.0 - 2013-09-30

  • Upgrading to Liquibase version 3.0.5 to add new required methods.

1.1.0 - 2013-08-10

  • Upgrade Liquibase version to 3.0.x.
  • Backward-compatible with previous version.

1.0.0 - 2012-04-04

  • Initial release.
  • Supports Liquibase 2.0.x.

liquibase-slf4j's People

Contributors

arlol avatar joschi avatar mattbertolini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

liquibase-slf4j's Issues

Log Level not properly detected

I'm using the following versions in my pom.xml:

    <dependency>
      <groupId>org.liquibase</groupId>
      <artifactId>liquibase-core</artifactId>
      <version>3.5.3</version>
    </dependency>
    <dependency>
      <groupId>com.mattbertolini</groupId>
      <artifactId>liquibase-slf4j</artifactId>
      <version>2.0.0</version>
    </dependency>

In my log4j.properties I use the following config:

log4j.logger.liquibase=INFO

I'm still getting this output:

2017-07-19 19:19:06,521 [DEBUG] Slf4jLogger:137 - Found namespace details class liquibase.parser.core.xml.StandardNamespaceDetails for http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
2017-07-19 19:19:06,522 [DEBUG] Slf4jLogger:137 - Local path for http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd is liquibase/parser/core/xml/dbchangelog-3.5.xsd
2017-07-19 19:19:06,526 [DEBUG] Slf4jLogger:137 - Successfully loaded XSD from liquibase/parser/core/xml/dbchangelog-3.5.xsd

What am I doing wrong?

Liquibase-sfl4j does not seem to work with liquibase 3.5.3.

I am running Liquibase-slf4j with Liquibase3.5.3 in a JBOSS EAP 7.0 server.
After adding the dependency to ma application pom.vl and running my application, Liquibase still is logging everything to stderr.
From the documentation , adding the dependency is the only thing to do to make it work. Can someone help me finding the problem???

Regards,
Jan van de Klok

Liquibase CLI fails with (com.mattbertolini.liquibase.logging.slf4j.Slf4jLogService and liquibase.logging.core.JavaLogService are in unnamed module of loader 'app')

Trying to implement a gradle task for the diffChangeLog liquibase's command line command.

My dependencies:

    implementation("org.liquibase:liquibase-core:4.1.0")
    implementation("org.liquibase.ext:liquibase-hibernate5:4.1.0")
    runtimeOnly("com.mattbertolini:liquibase-slf4j:4.0.0")

The task

tasks.register<JavaExec>("liquibaseDiffChangelog") {
    description = "Runs Liquidbase diff between schema and current changeSet"
    group = "liquibase"
    classpath = sourceSets["main"].runtimeClasspath + configurations["liquidbase"]
    main = "liquibase.integration.commandline.Main"

    args("--changeLogFile=" + project.projectDir.toString() + "/src/main/resources/changelog-changesets.xml")
    args("--referenceUrl=hibernate:spring:**redacted**?dialect=org.hibernate.dialect.MySQL57Dialect")
    args("--username=sa")
    args("--password=sa")
    args("--url=jdbc:mysql://localhost:3306/**redacted**?useSSL=false&nullNamePatternMatchesAll=true")
    args("--driver=com.mysql.cj.jdbc.Driver")
    args("diffChangeLog")
}

it gives me

▶ ./gradlew liquibaseDiffChangelog

> Task :liquibaseDiffChangelog FAILED
16:38:12,437 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
16:38:12,438 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
16:38:12,439 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/**redacted**/build/resources/main/logback.xml]
16:38:12,553 |-INFO in ch.qos.logback.classic.joran.action.LoggerContextListenerAction - Adding LoggerContextListener of type [ch.qos.logback.classic.jul.LevelChangePropagator] to the object stack
16:38:12,554 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@7c7b252e - Propagating DEBUG level on Logger[ROOT] onto the JUL framework
16:38:12,554 |-INFO in ch.qos.logback.classic.joran.action.LoggerContextListenerAction - Starting LoggerContextListener
16:38:12,556 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
16:38:12,558 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
16:38:12,563 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
16:38:12,817 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.AsyncAppender]
16:38:12,819 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [ASYNC]
16:38:12,819 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to ch.qos.logback.classic.AsyncAppender[ASYNC]
16:38:12,819 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC] - Attaching appender named [STDOUT] to AsyncAppender.
16:38:12,819 |-INFO in ch.qos.logback.classic.AsyncAppender[ASYNC] - Setting discardingThreshold to 51
16:38:12,820 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [liquibase] to INFO
16:38:12,821 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@7c7b252e - Propagating INFO level on Logger[liquibase] onto the JUL framework
16:38:12,821 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.fieldlens] to DEBUG
16:38:12,821 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@7c7b252e - Propagating DEBUG level on Logger[com.fieldlens] onto the JUL framework
16:38:12,821 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.wework.costmanagement] to INFO
16:38:12,821 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@7c7b252e - Propagating INFO level on Logger[com.wework.costmanagement] onto the JUL framework
16:38:12,821 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
16:38:12,821 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@7c7b252e - Propagating INFO level on Logger[ROOT] onto the JUL framework
16:38:12,821 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [ASYNC] to Logger[ROOT]
16:38:12,821 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
16:38:12,822 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@64e7619d - Registering current configuration as safe fallback point
Unexpected error running Liquibase: class com.mattbertolini.liquibase.logging.slf4j.Slf4jLogService cannot be cast to class liquibase.logging.core.JavaLogService (com.mattbertolini.liquibase.logging.slf4j.Slf4jLogService and liquibase.logging.core.JavaLogService are in unnamed module of loader 'app')
For more information, please use the --logLevel flag
2020-10-13 16:38:12.850 [main   ] ERROR l.integration.commandline.Main$1 - Unexpected error running Liquibase: class com.mattbertolini.liquibase.logging.slf4j.Slf4jLogService cannot be cast to class liquibase.logging.core.JavaLogService (com.mattbertolini.liquibase.logging.slf4j.Slf4jLogService and liquibase.logging.core.JavaLogService are in unnamed module of loader 'app')
java.lang.ClassCastException: class com.mattbertolini.liquibase.logging.slf4j.Slf4jLogService cannot be cast to class liquibase.logging.core.JavaLogService (com.mattbertolini.liquibase.logging.slf4j.Slf4jLogService and liquibase.logging.core.JavaLogService are in unnamed module of loader 'app')
        at liquibase.integration.commandline.Main$1.run(Main.java:276)
        at liquibase.integration.commandline.Main$1.run(Main.java:193)
        at liquibase.Scope.child(Scope.java:169)
        at liquibase.Scope.child(Scope.java:145)
        at liquibase.integration.commandline.Main.run(Main.java:193)
        at liquibase.integration.commandline.Main.main(Main.java:156)

Any recommendations?

issues with setup on liquibase 4.24.0

I'm trying to configure JSON logging for Liquibase with this:

export JAVA_OPTS="-Dlogback.configurationFile=liquibase.logback.xml"
# Run Liquibase update
bin/liquibase update --defaultsFile liquibase.properties --changeLogFile=changelog-master.yaml --classpath "$(printf %s: lib/*.jar)"

This entries are in the classpath:

  - /opt/liquibase
  - /opt/liquibase/lib/ecs-logging-core-1.5.0.jar
  - /opt/liquibase/lib/liquibase-slf4j-5.0.0.jar
  - /opt/liquibase/lib/logback-classic-1.2.11.jar
  - /opt/liquibase/lib/logback-core-1.2.11.jar
  - /opt/liquibase/lib/logback-ecs-encoder-1.5.0.jar
  - /opt/liquibase/lib/logstash-logback-encoder-7.4.jar
  - /opt/liquibase/lib/slf4j-api-1.7.3.jar
  - /opt/liquibase/lib/slf4j-simple-1.7.3.jar

But my logback config is not used. Any ideas?

Have you tried SLF4J 2.0.0?

We are using liquibase-slf4j 4.1.0 and have been using slf4j 1.7.36.

When we up it to slf4j 2.0.0 we get

java.lang.ClassCastException: class org.slf4j.helpers.NOPLoggerFactory cannot be cast to class ch.qos.logback.classic.LoggerContext (org.slf4j.helpers.NOPLoggerFactory and ch.qos.logback.classic.LoggerContext are in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @e077866)

Cannot find default log service

No matter what I do I get Cannot find default log service error trying to use liquibase. Every forum I read says to use this library but even included I still get Cannot find default log service error. Any assistance would be appreciated.

I verified both your class files are present in my Jar along with slf4j-simple. What am I missing? Using liquibase 4.29.1

Liquibase 3.4.0 - Always print info log message

I added the dependency liquibase-slf4j latest , but it doesnt seem to pick the logger Slf4jLogger during the startup on unit integration test, and always use the DefaultLogger.

Im using logback + slf4j.

i cannot control the level of the log from the logback configuration file (logback-test.xml), always print the INFO from liquibase

<logger name="liquibase" level="WARN" />

[INFO] +- org.springframework.data:spring-data-commons:jar:1.9.1.RELEASE:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.8:compile
[INFO] | - org.slf4j:jcl-over-slf4j:jar:1.7.8:runtime

[INFO] +- org.liquibase:liquibase-core:jar:3.4.0:test
[INFO] +- ch.qos.logback:logback-classic:jar:1.1.2:test
[INFO] | - com.mattbertolini:liquibase-slf4j:jar:1.2.1:test
[INFO] | - ch.qos.logback:logback-core:jar:1.1.2:test

How liquibase know to use Slf4jLogger and not DefaultLogger

Provide Liquibase SLF4J bridge as an OSGi fragment

In an OSGi runtime we also would like to bridge Liquibase 4.x's logging to SLF4J.

To get this working, Liquibase-SLF4J should be packaged as a fragment, with Liquibase core as the host bundle.
Then the Slf4JLogService can be discovered by Liquibase's ServiceLocator.

Cfr ongoing work and discussions:

I propose to prepare a PR for this?

Can't use with liquibase cli due to cast exception

Hello !

Basically, I have the exact same error as here: Issue

I am trying to run liquibase 4.17.2 as command line, I put in my classpath logback core and classic (1.4.5), slf4j-api (1.7.36) and liquibase-slf4j (4.1.0).

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Unexpected error running Liquibase: class com.mattbertolini.liquibase.logging.slf4j.Slf4jLogService cannot be cast to class liquibase.logging.core.JavaLogService (com.mattbertolini.liquibase.logging.slf4j.Slf4jLogService and liquibase.logging.core.JavaLogService are in unnamed module of loader java.net.URLClassLoader @6d06d69c)

For more information, please use the --log-level flag

The PR which could resolve that issue was not accepted into the main repository because it has been supposedly already corrected by another change, but it is not on my end. Do you have any workaround or way to solve ? Or should I send a new issue on the liquibase repository ?

Feel free to ask for any additional details :)

Not working with Liquibase 3.5.3

Not working with Liquibase 3.5.3, although works fine with 3.4.2. I understand this is probably an issue on Liquibase side again, so just FYI...

Does not work with 3.0.4/3.0.5

Liquibase 3.0.4 specifies two new methods for the logger setChangeSet and setChangeLog. These are not present in the current version of the logger.

I wanted to open a pull request to fix this but I've never work with Ivy and ivy test did not just work. Maybe add some documentation for this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.