1

I spent last few days for trying to set up logback with my wildfly 10 project.

My goal are:

  1. Server logs should be created by wildfly logger.
  2. My EAR logs should be created by logback.
  3. Logback and wildfly logger logs to console.

My project skeleton is generated by maven and is as follow:

  • projectname
  • projectname-ear
  • projectname-ejb
  • projectname-parent
  • projectname-web

I try to add logback.xml to resources in web and ejb project - it's not working. I'm new in wildfly and not sure if I am doing it right.

I tried to add following code to jboss-deployment-structure.xml in all projects according to this page:

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

Nothing happen. Then I fond another one:

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

Nothing happen at all. Am I doing something wrong in this moment?

Then I found solution with replacing wildfly logger in this tutorial.

It works but there is one huge disadvantage. Logs are doubled - it looks that logback and wildfly logger logging at once to console. Disabling wildfly logger in logger.properties doesn't work.

I had no idea that I spent so much time for implementing logger. Logback + android was a peace of cake. I appreciate all good advices and experience with this problem.

Community
  • 1
  • 1
LukaszTaraszka
  • 801
  • 1
  • 10
  • 26

1 Answers1

3

What you have with the jboss-deployment-structure.xml will work, but because you're using an EAR you'll need to do the same exclusions for each sub-deployment. I would just exclude the logging subsystem since you won't need any part of the subsystem processing your deployment.

Add jboss-deployment-structure.xml to Your EAR project into directory projectname-ear/src/main/application/META-INF.

Another option would be to change the add-logging-api-dependencies and the use-deployment-logging-config to false. The thing to note with this option is it will stop the logging dependencies from getting added to ALL deployments. If you've only got the one deployment or all your deployments us logback for the log manager, then this would be the easiest option.

Update: Example jboss-deployment-structure.xml

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <deployment>
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </deployment>
    <sub-deployment name="projectname-web.war">
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </sub-deployment>
    <sub-deployment name="projectname-ejb.jar">
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </sub-deployment>
</jboss-deployment-structure>

To remove duplicated logs check this post.

Community
  • 1
  • 1
James R. Perkins
  • 16,800
  • 44
  • 60
  • I added jboss-deployment-structure.xml to all sub-deployments into directory `src/main/resources/META-INF/` (EJB, WEB - other seems to be generated automatically). It unfortunately didn't help. The second part of Your answer works almost perfectly but there is still problem with console logs - they are 'wrapped' by wildfly logs. I see that @gandalfml had the same [problem](http://stackoverflow.com/questions/37377043/configure-logback-in-wildfly) and didn't solve it. – LukaszTaraszka Feb 18 '17 at 11:34
  • Sorry I should have clarified. You need to add the exclusion to the jboss-deployment-structure.xml in the EAR. You'll end up with some – James R. Perkins Feb 19 '17 at 19:40
  • I could stop with turning off wildfly logging in standalone.xml and live in peace, but I really want to check out Your first suggestion, so... I have read about sub-deployments and ear file. I found similar problems [here](http://stackoverflow.com/questions/26137219/war-in-ear-jboss-deployment-structure-xml-ignored) and [here](http://stackoverflow.com/questions/26859092/jboss-deployment-structure-xml-does-not-loads-the-dependencies-in-my-ear-project). Sorry for my noob question but how to add jboss-deployment-structure.xml to my EAR project? – LukaszTaraszka Feb 21 '17 at 19:33
  • I've added an example to the question. The file just needs to be in the `EAR/META-INF` directory. – James R. Perkins Feb 22 '17 at 21:22
  • Not in `EAR/META-INF` but in `EAR/src/main/application/META-INF`!!! [More](https://developer.jboss.org/thread/172482). What about doubled logs in wildfly console? Example: `22:28:31,355 INFO [stdout] (ServerService Thread Pool -- 61) 22:28:31.355 [ServerService Thread Pool -- 61] TRACE c.t.s.a.v1.endpoints.DialogEndpoint - TRACE` - here my logback TRACE level log has been wrapped by wildfly INFO level log. – LukaszTaraszka Mar 01 '17 at 21:37
  • By `EAR/META-INF` I meant the packaged EAR not the project. For the output have a look at http://stackoverflow.com/a/42517232/152794. – James R. Perkins Mar 02 '17 at 01:21