Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slf4j binding issues #231

Open
hazendaz opened this issue Jul 13, 2015 · 1 comment
Open

Slf4j binding issues #231

hazendaz opened this issue Jul 13, 2015 · 1 comment

Comments

@hazendaz
Copy link
Member

Review slf4j/logback binding issues when running waffle at container layer. See https://github.com/grgrzybek/tomcat-slf4j-logback on how to approach this unless better solution is found

@ljluestc
Copy link

To resolve SLF4J binding issues, follow these steps:

Step 1: Ensure Only One SLF4J Binding is Present
Remove all unnecessary SLF4J bindings from your application and container.

For example, if you are using Logback, ensure that only slf4j-logback is in the classpath, and remove slf4j-log4j or other bindings.

Step 2: Use the Correct SLF4J Version
Ensure that the SLF4J API (slf4j-api) and the binding (e.g., slf4j-logback) are compatible versions.

For example:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>2.0.9</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.4.11</version>
</dependency>

Step 3: Configure Logging at the Container Level
Use the approach described in tomcat-slf4j-logback to configure SLF4J and Logback at the Tomcat container level.

This involves:

Adding the necessary SLF4J and Logback JARs to Tomcat's lib directory.

Configuring Logback via a logback.xml file placed in Tomcat's conf directory.

Step 4: Exclude Conflicting Dependencies
If you are using a build tool like Maven or Gradle, exclude conflicting logging dependencies from your dependencies.

For example, in Maven:

<dependency>
    <groupId>com.github.waffle</groupId>
    <artifactId>waffle-jna</artifactId>
    <version>3.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Step 5: Use a Parent-First ClassLoader
In Tomcat, configure the classloader to use a parent-first strategy for loading SLF4J classes. This ensures that the container-level SLF4J binding is used instead of the application-level binding.

Add the following to your context.xml:

<Context>
    <Loader delegate="true"/>
</Context>
  1. Example Configuration
    Here’s an example of how to configure SLF4J and Logback in a Tomcat environment:

Step 1: Add SLF4J and Logback JARs to Tomcat
Place the following JARs in Tomcat's lib directory:

slf4j-api-2.0.9.jar

logback-classic-1.4.11.jar

logback-core-1.4.11.jar

Step 2: Configure Logback
Create a logback.xml file in Tomcat's conf directory:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

Step 3: Exclude Conflicting Dependencies in Your Application
In your pom.xml, exclude conflicting logging dependencies:

<dependency>
    <groupId>com.github.waffle</groupId>
    <artifactId>waffle-jna</artifactId>
    <version>3.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Step 4: Configure Tomcat ClassLoader
Add the following to your context.xml:

<Context>
    <Loader delegate="true"/>
</Context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants