Skip to content
Advertisement

SLF4J logging with jboss/wildfly 10

I have a Java webapp running in a WildFly 10 server. I used to have the following libraries as Maven dependencies:

        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>

        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>

        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>

        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>

I would now like to use wildfly’s builtin logging subsystem.

  • Which libraries do I need to add to my project(s)?
  • How do I configure the default log-category and root logger declared in standalone.xml to log everything from packages “com.mycompany” at level “debug”?
  • I’m running the wildfly server as a plugin in my eclipse. By using the console handler, I want the logs to be written to the console of Eclipse

Currently, it isn’t working and I’m not sure which of the 3 steps have I have misconfigured. Here’s a snippet from standalone.xml:

 ...            
        <logger category="com.company">
            <level name="DEBUG"/>
        </logger>
        <root-logger>
            <level name="DEBUG"/>
            <handlers>
                <handler name="CONSOLE"/>
                <handler name="FILE"/>
            </handlers>
        </root-logger>
 ...

Advertisement

Answer

What you have in your standalone.xml is correct. However you’re including too many slf4j dependencies. slf4j is meant to be a logging facade first. There is no need to include implementation dependencies in your application.

First you’ll want to remove the log4j2 dependencies from your pom. Then mark the org.slf4j:slf4j-api as <scope>provided</scope> as the container already provides that dependency for you. That should be all you need to do.

Advertisement