Wildfly disabling logging subsystem - java

in my web application i need to use my logging framework. The framework is loaded by each webapplication like a jar dependency.
In order to disable jboss logging subsystem i tried to create a
jboss-deployment-structure.xml
file copied in:
(firt try)- webapplication.war\WEB-INF\
(second try) - webapplication.war\WEB-INF\lib\my_framework.jar\META-INF\
the content of the file is:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.jboss.as.logging (or org.jboss.logging)" />
</exclusions>
</deployment>
But nothing seems to change in the log process.
I checked the framework MANIFEST.MF and no other dependencies are imported.
I also realized that by cancelling the logging subsystem from standalone.xml the custom logging framework works fine.

You can exclude subsystems from deployments with in the jboss-deployment-structure.xml as well. Excluding the module does not exclude the subsystem from processing the deployment.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
Excluding the subsystem will stop the deployment from being processed by the subsystem.

Related

What is wrong with my jboss-deployment-structure.xml? I'm trying to exclude a dependancy. The exclusion works in WAR but not in EAR

So we have found that JBoss 7.1 EAP provides its own version of Jackson-Databind. This version interferes with our deployment as we have a newer version in the WAR. We've proven out this theory by including this jboss-deployment-structure.xml at the WAR level's WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="jaxrs"/>
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
This lets the WAR deploy on its own without errors when it previously received the errors.
However, when trying to implement the same solution at the EAR level of deployment I've been unsuccessful. I've tried putting the jboss-deployment-structure.xml in the META-INF, WEB-INF, and root level of the EAR. I've done that with all number of different configurations but I can't get it to correctly exclude jaxrs. It's worth mentioning that this is my first run on JBoss configurations and I could be missing something incredibly simple.
EAR level file:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclude-subsystems>
<subsystem name="jaxrs" />
</exclude-subsystems>
</deployment>
<sub-deployment name="myWar.war">
<exclude-subsystems>
<subsystem name="jaxrs" />
</exclude-subsystems>
</sub-deployment>
</jboss-deployment-structure>
So, turns out that this was the answer. Just as it stands here. Another developer put the same file into his build and it worked. I don't know what the difference was between his environment and mine but I'm marking this question resolved.

Jboss EAP 7 - How to exclude implicit modules from deployment (javax.jms)?

I didn't think I would end up here but after a lot of Google and StackOverflow searches here I'm.
This is my exact problem except that I can't afford to make code changes.
The WAR I'm trying to deploy includes a JMS library (i.e. javax.jms, which I cannot exclude form the WAR.) which is already loaded by Jboss EAP 7 by default. The path to jar is something like this jboss/modules/system/layers/base/javax/jms/api/ain/jboss-jms-api_2.0_spec-1.0.0.Final-redhat-1.jar. Because of this two different versions of the same classes loading I'm getting ClassCastException.
org.apache.activemq-ra.ActiveMQConnectionFactory cannot to be cast to javax.jms.ConnectionFactory
So, I want Jboss to NOT load javax.jms so that my application can use the JAR included with the WAR.
So, I was wondering if there was any way to exclude the module globally (for all WAR deployments).
Excluding it per deployment would work too. And I do realize it can be acheivd using jboss-deployment-structure.xml but I can't get it to work.
Here is what I tried:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure
xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclude-subsystems>
<subsystem name="javax" />
<subsystem name="javax.jms" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
and
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure
xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclusions>
<module name="javax" />
<module name="javax.jms" />
<module name="javax.jms.api" />
</exclusions>
</deployment>
</jboss-deployment-structure>
I placed the file in WEB-INF directory. It didn't work. It still loaded the JMS class from modules folder of Jboss EAP. So, how do I correctly do this?
The correct jboss-deployment-structure.xml is here:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclude-subsystems>
<subsystem name="messaging-activemq"></subsystem>
</exclude-subsystems>
<exclusions>
<module name="javax.jms.api"></module>
</exclusions>
</deployment>
</jboss-deployment-structure>
This way you exclude both messaging subsystem and the JMS api.
You should remove the JMS API JAR from your deployment. You can still keep the JMS implementation JAR in your deployment but that should probably end up in a RAR, preferably outside your deployment.
This link has some things you could try.
Notably:
I think the problem is that activemq-all-5.4.2.jar contains javax.jms.*. Your deployment already gets this implicitly from the javaee.api module (see more information about implicity module dependencies here). I don't think it is appropriate for an application module/jar to package Java EE interfaces. You can try simply deleting the javax directory from activemq-all-5.4.2.jar or using a different set of ActiveMQ jars in your module to limit it to only what you need.
and/or altering your module.xml for ActiveMQ
<module xmlns="urn:jboss:module:1.0" name="activemq">
<resources>
<resource-root path="activemq-all-5.4.2.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
There appears to be a method to embed ActiveMQ in Jboss as well, if you're interested. I won't pull out information from that article, as it doesn't answer the original question.

How to prevent application logs getting logged in server.log in Wildfly 8.2.0 Final AS

I am migrating an EAR application from JBoss 6.1.0 AS to Wildfly 8.2.0 AS. EAR contains log4j.xml and application logs are generated by using this logging configuration file by employing the below line of code:
org.apache.log4j.xml.DOMConfigurator.configureAndWatch(log4j file path)
Application logs are generated fine but in server.log, application logs are also getting appended. I am using standalone-full-ha.xml configuration file and tried the below steps:
Added jboss-deployment-structure.xml with the following contents:
<deployment>
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
</deployment>
Added below lines under <subsystem xmlns="urn:jboss:domain:logging:2.0"> section
in standalone-full-ha.xml.
<use-deployment-logging-config value="true"/>
<add-logging-api-dependencies value="false"/>
How can I prevent applications logs getting appended in server.log ? Please help.
Workaround tried
Just adding to my previous comments, I tried first option provided in the link http://www.mastertheboss.com/jboss-server/jboss-log/using-log4j-with-jboss-as-7-and-wildfly.
Added log4j.xml under META-INF of EAR.
Added org.apache.log4j module as one of the dependencies attribute in MANIFEST.MF.
It was mentioned to add a VM argument -Dorg.jboss.as.logging.per-deployment=true but I did not add.
server.log is generated fine and application logs are getting generated fine but I have below concerns:
is the starting tag in log4j.xml and it has "warn" as value of threshold attribute. But, I am getting all kind of logs (i.e. works as ALL or DEBUG threshold).
I have placed log4j.xml in META-INF of EAR. So, will org.apache.log4j.xml.DOMConfigurator.configureAndWatch(log4j file path) work where path denotes log4j.xml in META-INF ? Default time out is 60 seconds and if I change threshold, will it reflect ?
I use following jboss-deployment-structure.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--https://github.com/wildfly/wildfly-core/blob/master/server/src/main/resources/schema/jboss-deployment-structure-1_2.xsd-->
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
<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>

SLF4J logs are not coming in the specific error/trace file. It is coming in server.log

I am programming in Java. I have used executor service. Logs are printing in the specified trace.log file for the main thread. But for the threads created by the executor service, logs are getting printed in the Jboss server.log. How to get these logs in the trace.log instead of in server.log?
I found the concurrency should not affect the functionality of slf4j.
Is SLF4J good to be used in a multithreaded application for logging to a database?
Could somebody please tell what am I missing here?
Thanks in advance.
You have to exclude SLF4J from JBoss. You can do it with jboss-deployment-structure.xml
My jboss-deployment-structure is located in EAR module under resources/META-INF folder and looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<exclusions>
<module name="org.slf4j" slot="main" />
<module name="org.slf4j.impl" slot="main" />
</exclusions>
</deployment>
<sub-deployment name="some-war.war">
<exclusions>
<module name="org.slf4j" />
<module name="org.slf4j.impl" />
</exclusions>
</sub-deployment>
In some-war.war module I can use logback which logs properly into defined files.

are ejb and jars subdeployments in an EAR

I've been having problems with jboss/logback and I made a jboss-deployment-structure.xml and it looks like this
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding
some dependencies -->
<exclusions>
<module name="org.apache.commons.logging" />
<module name="org.slf4j" />
<module name="org.slf4j.ext" />
<module name="org.slf4j.impl" />
<module name="org.apache.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
this is in the META-INF folder of the EAR, but now I've been thinking... the EAR also has a lib folder that has:
slf4j-api.jar,
logback-classic.jar,
logback-core.jar, and
log4j-over-slf4j.jar
as well as the other two other ejb projects wrapped up in it during deployment time.
my question is, do I have to specify the jars and other other ejb projects as sub-deployments in the jboss-deployment-structure.xml??
also, the jboss-deployment-structure.xml has been basically ignored everytime I deploy the ear and start the server, i know this because the server still is accessing the exclusions i have declared, is the xml in the right spot in the meta-inf of the ear?
thank you for the help
Yes I added the jars as subdeployments and fixed errors

Categories