26

I run web application in WildFly 8 and for some reason it does not log. I use SLF4J with LOGBACK. The log file is created on deploy but it is empty. I do not see my log statements in wildfly logs either.

The class contains:

package com.blah.oops;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

static final Logger log = LoggerFactory.getLogger(EndpointImpl.class);

log.debug("request called");

War contains:

  • WEB-INF\lib\slf4j-api-1.7.5.jar
  • WEB-INF\lib\logback-classic-1.1.1.jar
  • WEB-INF\lib\logback-core-1.1.1.jar
  • WEB-INF\classes\logback.xml

Configuration file logback.xml contains:

<configuration scan="true" scanPeriod="10 seconds">
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>${LOG_PATH}/backend-main.log</file>
        <encoder>
            <pattern>%date %level [%thread] %logger{10} %msg%n</pattern>
        </encoder>
    </appender>

    <!-- PROFILER configuration -->
    <turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
        <Marker>PROFILER</Marker>
        <OnMatch>ACCEPT</OnMatch>
        <!--  <OnMatch>DENY</OnMatch> -->
    </turboFilter>

    <logger name="org.eclipse.jetty.util.log" level="info"/>
    <logger name="com.blah" level="debug"/>
    <logger name="org.apache.cxf" level="warn"/>

    <root level="info">
        <appender-ref ref="FILE"/>
    </root>
</configuration>

console.log contains logback initialization:

.[0m.[0m10:19:52,716 INFO  [stdout] (MSC service thread 1-2) 10:19:52,489 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
.[0m.[0m10:19:52,717 INFO  [stdout] (MSC service thread 1-2) 10:19:52,489 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
.[0m.[0m10:19:52,717 INFO  [stdout] (MSC service thread 1-2) 10:19:52,490 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [vfs:/content/backend.war/WEB-INF/classes/logback.xml]
.[0m.[0m10:19:52,717 INFO  [stdout] (MSC service thread 1-2) 10:19:52,501 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@666dc663 - URL [vfs:/content/backend.war/WEB-INF/classes/logback.xml] is not of type file
.[0m.[0m10:19:52,717 INFO  [stdout] (MSC service thread 1-2) 10:19:52,524 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
.[0m.[0m10:19:52,717 INFO  [stdout] (MSC service thread 1-2) 10:19:52,529 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Setting ReconfigureOnChangeFilter scanning period to 10 seconds
.[0m.[0m10:19:52,718 INFO  [stdout] (MSC service thread 1-2) 10:19:52,529 |-INFO in ReconfigureOnChangeFilter{invocationCounter=0} - Will scan for changes in [[]] every 10 seconds.
.[0m.[0m10:19:52,718 INFO  [stdout] (MSC service thread 1-2) 10:19:52,529 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Adding ReconfigureOnChangeFilter as a turbo filter
.[0m.[0m10:19:52,718 INFO  [stdout] (MSC service thread 1-2) 10:19:52,532 |-ERROR in ch.qos.logback.core.joran.action.PropertyAction - Could not find resource [acquirer.properties].
.[0m.[0m10:19:52,718 INFO  [stdout] (MSC service thread 1-2) 10:19:52,532 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
.[0m.[0m10:19:52,718 INFO  [stdout] (MSC service thread 1-2) 10:19:52,535 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [jettyConsole]
.[0m.[0m10:19:52,718 INFO  [stdout] (MSC service thread 1-2) 10:19:52,572 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
.[0m.[0m10:19:52,719 INFO  [stdout] (MSC service thread 1-2) 10:19:52,573 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE]
.[0m.[0m10:19:52,719 INFO  [stdout] (MSC service thread 1-2) 10:19:52,575 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
.[0m.[0m10:19:52,719 INFO  [stdout] (MSC service thread 1-2) 10:19:52,576 |-INFO in ch.qos.logback.core.FileAppender[FILE] - File property is set to [/var/log/blah/backend-main.log]
.[0m.[0m10:19:52,719 INFO  [stdout] (MSC service thread 1-2) 10:19:52,591 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.eclipse.jetty.util.log] to INFO
.[0m.[0m10:19:52,719 INFO  [stdout] (MSC service thread 1-2) 10:19:52,592 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.blah] to DEBUG
.[0m.[0m10:19:52,719 INFO  [stdout] (MSC service thread 1-2) 10:19:52,592 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.cxf] to WARN
.[0m.[0m10:19:52,720 INFO  [stdout] (MSC service thread 1-2) 10:19:52,592 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
.[0m.[0m10:19:52,720 INFO  [stdout] (MSC service thread 1-2) 10:19:52,713 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to Logger[ROOT]
.[0m.[0m10:19:52,720 INFO  [stdout] (MSC service thread 1-2) 10:19:52,713 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
.[0m.[0m10:19:52,720 INFO  [stdout] (MSC service thread 1-2) 10:19:52,714 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@30fbc21e - Registering current configuration as safe fallback point

It seems to me that LOGBACK is successfully configured. But log messages are lost. Any idea what is going there? It makes me no sense.

1

3 Answers 3

34

WildFly adds slf4j as a default logging dependency Have you tried excluding the main implementation in jboss-deployment-structure.xml descriptor (It should go under the META-INF directory). This can be done with below lines:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
  <deployment>
    <exclusions>
      <module name="org.apache.commons.logging" />
      <module name="org.apache.log4j" />
      <module name="org.jboss.logging" />
      <module name="org.jboss.logging.jul-to-slf4j-stub" />
      <module name="org.jboss.logmanager" />
      <module name="org.jboss.logmanager.log4j" />
      <module name="org.slf4j" />
      <module name="org.slf4j.impl" />
    </exclusions>
  </deployment>
</jboss-deployment-structure>
7
  • 2
    I just found following question and exclusion of <subsystem name="logging" /> helped. Thanks nevermind. stackoverflow.com/questions/21846329/… Apr 15, 2014 at 9:54
  • So am I. It is interesting that Similar questions are different when you type your question and when the question is actually submitted. Apr 15, 2014 at 9:59
  • 1
    IMO: I would use the logging facilities the server already provides though. Bit strange that it is on the application's classpath by default though, in JBoss 7.x I had to put the logging module explicitly ON the application's classpath.
    – Gimby
    Apr 16, 2014 at 15:09
  • Works in jboss as 7.1.1.Thanks!!
    – JRichardsz
    Aug 19, 2016 at 23:09
  • 1
    When using Maven (or Eclipse / Maven), the JBoss descriptor must be placed in src/main/webapp/META-INF/jboss-deployment-structure.xml. Do NOT place it under src/main/resources/META-INF/.... Aug 22, 2016 at 13:45
11

Wildfly is using slf4j as defult logging. you have to tell jboss not to use slf4j, i am using log4j. you can do this using below jboss-deployment-structure.xml

<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>
0

Assuming your container supports child-first class loading, separation of logging can be accomplished by embedding a copy of slf4j and logback jar files in each of your applications.

For web-applications, placing slf4j and logback jar files under the WEB-INF/lib directory of the web-application is sufficient to endow each web-application with a separate logging environment. A copy of the logback.xml configuration file placed under WEB-INF/classes will be picked up when logback is loaded into memory.

By virtue of class loader separation provided by the container, each web-application will load its own copy of LoggerContext which will pickup its own copy of logback.xml.

You can follow the solution config steps described on this post:

https://www.hhutzler.de/blog/using-logback-for-your-wildfly-project/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.