Override logging in WildFly

Rinat Mukhamedgaliev picture Rinat Mukhamedgaliev · Feb 18, 2014 · Viewed 28.6k times · Source

I used tomcat and simply override default logging system. How to enable logging with logback on wildfly in my spring app?

My Logback.xml owrking on tomcat

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <encoder>
            <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
        </encoder>
    </appender>

    <logger name="org.springframework" level="WARN" />
    <logger name="com.citronium.planstery" level="INFO" />
    <logger name="org.apache.http.impl.conn.tsccm" level="ERROR" />

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

Answer

James R. Perkins picture James R. Perkins · Feb 19, 2014

You can use logback to configure logging in your application. You can't use logback to configure logging for the server.

To use logback in your configuration you'll need to change the add-logging-api-dependencies to false or create a jboss-deployment-structure.xml that excludes the subsystem. You'll also need to include logback and slf4j in your deployment.

The first option of changing the add-logging-api-dependencies is a global setting for all deployments. The follow CLI command will change the value:

/subsystem=logging:write-attribute(name=add-logging-api-dependencies,value=false)

This option simply doesn't add any of the implicit logging dependencies to your deployment.

The second option of using a jboss-deployment-structure.xml will disable the logging subsystem for your deployment only. The following is an example file:

<jboss-deployment-structure>
  <deployment>
     <!-- exclude-subsystem prevents a subsystems deployment unit processors running on a deployment -->
     <!-- which gives basically the same effect as removing the subsystem, but it only affects single deployment -->
     <exclude-subsystems>
        <subsystem name="logging" />
    </exclude-subsystems>
  </deployment>
</jboss-deployment-structure>