问题
I spent last few days for trying to set up logback with my wildfly 10 project.
My goal are:
- Server logs should be created by wildfly logger.
- My EAR logs should be created by logback.
- 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.
回答1:
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.
来源:https://stackoverflow.com/questions/42243943/wildfly-10-logback