JBoss AS 7.1.1 Final and Log4j + Not working - java

In my pom.xml, I added below dependency
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
And as suggested in jboss forum, i added below jboss-deployment-structure.xml under WEB-INF in war project.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
But still server log is print, no application logs in my console.
My log4j.properties in classpath has below setting.
log4j.rootLogger=DEBUG, consoleAppender, fileAppender
# Redirect log messages to console
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppender.MaxFileSize=5MB
log4j.appender.fileAppender.MaxBackupIndex=10
log4j.appender.fileAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.fileAppender.File=${jboss.server.base.dir}/log/wm/sample.log
Console log what i am getting is below
09:35:36,122 WARN [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015850: /C:/Mohan/Software/jboss-as-7.1.1.Final/standalone/deployments/wm.ear/wm-web-0.0.1-SNAPSHOT.war/WEB-INF/jboss-deployment-structure.xml in subdeployment ignored. jboss-deployment-structure.xml is only parsed for top level deployments.
Can somebody help me in pointing what am i missing in the above set?
Edit:
Structure of my application is - Each will have its own pom.xml and parent will have common pom.xml. I have added all slf4j related dependency in war pom.xml.
parent (pom.xml)
|
|__ear (pom.xml)
|
|__war (pom.xml)
|
|__test (pom.xml)

If you are using Spring you can configure your log4j from the web.xml
<!-- Logging listener -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>file:yourpath/log4j.properties</param-value>
<!-- You can also define yourpath with a environment variable and use it like file:${env_variable_path}/log4j.properties -->
</context-param>
Also, if you are still having problems you can you try with theese exclusions in your jboos-deployment-structure.xml
<exclusions>
<module name="org.apache.log4j" />
<module name="org.slf4j" />
<module name="org.apache.commons.logging" />
<module name="org.log4j" />
<module name="org.jboss.logging" />
</exclusions>
I think you need to overide other logging mechanisms.

Firstly, wouldn't setting <scope>provided</scope> in your war's pom do just fine?
Anyway, from the log you get I can see you deploy the war as part of ear archive. You need to reflect the fact in the jboss-deployment-structure.xml.
To find out how refer to JBoss AS7 docs, or documentation of whatever JBoss server you use.
Just an overview:You put your jboss-deployment-structure.xml into the ear archive. In the xml you have to define the war's configuration as subdeployment:
<jboss-deployment-structure>
<deployment>
....
</deployment>
<sub-deployment name="wm-web-0.0.1-SNAPSHOT.war">
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</sub-deployment>
</jboss-deployment-structure>

Related

How to make Log4J2 working in JBoss EAP 6.4

I have seen successful instance online to make Log4J2 works in JBoss EAP 6.x
My local war file has specific situation (JBoss EAP 6.4, JDK8):
The war is built on Spring 3 framework, where most logging is made by Apache Common Logging
Logging of the source code in the war is made by Slf4J
However, some in house dependencies in WEB-INF/lib is still made by Log4J 1.2, not slf4J
So I added following dependency to the project, listed below (only list the jar file instead of verbose pom xml):
### spring framework from jcl to slf4j
jcl-over-slf4j-1.7.25.jar
### slf4j to log4j 1.2 then to log4j2
slf4j-log4j12-1.7.25.jar
log4j-1.2-api-2.11.1.jar
### slf4j to log4j 2
slf4j-api-1.7.25.jar
slf4j-simple-1.7.25.jar
log4j-api-2.8.2.jar
log4j-core-2.8.2.jar
log4j-slf4j-impl-2.8.jar
My plan is to tell EAP 6.4 to never use any logging module from JBoss, instead just use whatever is provided from this war, so in the jboss-deployment-structure.xml I create following elements
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
<dependencies>
<module name="oracle" />
</dependencies>
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
<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' />
<module name='org.slf4j.jcl-over-slf4j' />
</exclusions>
</deployment>
</jboss-deployment-structure>
And when the application starts, I can see following information show up in the server log, extracted here
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/jcl-over-slf4j-1.7.25.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/slf4j-log4j12-1.7.25.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/slf4j-api-1.7.25.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/slf4j-simple-1.7.25.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/log4j-1.2-api-2.11.1.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/log4j-api-2.8.2.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/log4j-core-2.8.2.jar" to module deployment.MyApp.war:main
Adding resource "/C:/Windows/content/MyApp.war/WEB-INF/lib/log4j-slf4j-impl-2.8.jar" to module deployment.MyApp.war:main
there is not much further information regarding logging in the server log, no error.
However no matter how I configure the log appender (ROL or Console), there is no log4J log generated. I use FileAppender but there is no log file generated.
I don't think it is caused by log4J configuration issue, because same war file with the same log4J2.xml the logging output fine in Tomcat 8
How can I make this right so at least the application output logging successfully.
There are multiple SLF4J bindings in your dependencies:
slf4j-simple-1.7.25.jar
slf4j-log4j12-1.7.25.jar
log4j-slf4j-impl-2.8.jar
Action 1: Remove slf4j-simple and choose one of slf4j-log4j12 or log4j-slf4j-impl.
Beside that, TWO API dependencies for log4j look suspicious:
log4j-1.2-api-2.11.1.jar
log4j-api-2.8.2.jar
Action 2: Remove log4j-1.2-api-2.11.1.jar since you use implementation version 2.8.2 of log4j.

No logging from Hibernate-4.x on WildFly-8

The question is for the webapp WAR with Spring+Hibernate deployed to WF8.
After webapp upgrade from Hibernate-3.x to 4.x the Hibernate logging stopped working.
The Hibernate-3.x was using Slf4j. The Hibernate Log4j logging was configured in the webapp with declaration in jboss-deployment-structure.xml:
<exclusions>
<module name="org.apache.log4j"/>
<module name="org.slf4j"/>
<module name="org.slf4j.impl"/>
</exclusions>
This declaration makes all logging classes to be loaded from WAR, not WF8.
The Hibernate-4.x is using jboss-logging. The additional exclusion
<exclusions>
<module name="org.jboss.logging"/>
. . .
</exclusions>
initializes the webapp logger correctly but also breaks WF8 with Log4j error:
log4j:WARN No appenders could be found for logger (org.jboss.logging).
Questions:
• How to enforce loading classes from jboss-logging-3.x.Final.jar
in the webapp and ignore classes loaded from this jar in WF8?
• How to initialize jboss-logging in the webapp and not to break
the WF8?
See also https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly
Excluding JPA does not help:
<exclude-subsystems>
<subsystem name="jpa"/>
</exclude-subsystems>

Wildfly logging module exclusion does not work for a large web app

I've written a small web app which disables Wildfly 10.1's slf4j implementation and uses its own logging libraries (logback). It works fine because LoggerFactory.getILoggerFactory() resolves to ch.qos.logback.classic.LoggerContext as result.
But then I use the same code for a larger application (with 52 jar files in WEB-INF/lib/) LoggerFactory.getILoggerFactory() still resolves to a JBoss implementation org.slf4j.impl.Slf4jLoggerFactory, as by default.
How can I investigate what exactly retains server's logging instead of the one of mine? (And fix the situation of course.)
Maven dependencies used: "slf4j-api" 1.6.1, "logback-classic" and "logback-core" 0.9.28.
File jboss-deployment-structure.xml, which is known to be located properly in both cases:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<exclusions>
<module name="org.apache.common.logging"/>
<module name="org.apache.log4j"/>
<module name="org.jboss.log4j"/>
<module name="org.jboss.log4j.logmanager"/>
<module name="org.jboss.logging"/>
<module name="org.slf4j"/>
<module name="org.slf4j.impl"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
I know it's a old topic but i had a similar problem.
So, i will describe the problem and what i done to solve it.
I'm using spring-boot in my web application and running with jboss wildfly 10.
When i try to integrate sentry and logback on my project, the application reads the file logback.xml but use another logging system.
I realized that wildfly was ignoring logback and using jboss-logging instead.
So, i disabled the jboss logging module and than, my application started using logback and everything worked fine.
But this is how i disabled logging sub-system:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclude-subsystems>
<subsystem name="logging" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
The link when i found my anwser:

Need to exclude apache httpcomponent from jboss 6.4 module

We have recently migrated from jboss 6.1 eap to 6.4 eap, but facing problem of class loading.
In my project lib We need to use apache httpcore 4.4.1, but apache httpcore 4.3.3 is included in 6.4. This previously wasn't a problem when we were using jboss 6.1 because the resteasy-jaxrs module.xml did not export httpcore library.
Now with jboss 6.4 we are getting exception :
Caused by: java.lang.NoSuchMethodError: org.apache.http.util.Asserts.check(ZLjava/lang/String;Ljava/lang/Object;)V
Its because runtime my project is using jar available from jboss and which does not having this method with required signature.
Now I want to force my application to not to use jboss jar and use jar available from web-inf/lib folder.
I have try to exclude this via jboss-deployment-structure.xml but somehow it is not working and still it is using jar from jboss only.
below is snap from the jboss-deployment-structure.xml file.
<deployment>
<exclusions>
<module name="org.apache.httpcomponents" />
</exclusions>
<dependencies>
module name="org.apache.httpcomponents" />
</dependencies>
</deployment>
Can someone please help me on this what is missing here or is there any alternative for this...
Since you are using JBoss EAP, you can apply the CP07 patch for EAP 6.4 (so your version would be JBoss EAP 6.4.7) where this issue has been addressed. I would highly recommend applying the CP07 patch.
Alternatively, you can set <module name="org.apache.httpcomponents" export="false"/> in the $JBOSS_MODULES\org\jboss\resteasy\resteasy-jaxrs\main\module.xml.
However, I would recommend applying the patch as the recommended solution. This way you will not modify the configuration that is shipped with the product.
To resolve the issue we can take one of the below approach.
Change $JBOSS_MODULES\org\jboss\resteasy\resteasy-jaxrs\main\module.xml
as suggested by CoolBeans.
You can use below option if you have no control(or not authorized) to update the Jboss server configuration.
Add below xml configuration in your jboss-deployment-structure.xml file
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclude-subsystems>
<subsystem name="resteasy"/>
<subsystem name="jaxrs"/>
</exclude-subsystems>
<!-- Exclusions allow you to prevent the server from automatically adding
some dependencies -->
<exclusions>
<module name="javax.ws.rs.api"/>
<module name="org.jboss.as.jaxrs"/>
<module name="org.jboss.resteasy.resteasy-atom-provider" />
<module name="org.jboss.resteasy.resteasy-cdi" />
<module name="org.jboss.resteasy.resteasy-jaxrs" />
<module name="org.jboss.resteasy.resteasy-jaxb-provider" />
<module name="org.jboss.resteasy.resteasy-jackson-provider" />
<module name="org.jboss.resteasy.resteasy-jackson2-provider" />
<module name="org.jboss.resteasy.resteasy-jsapi" />
<module name="org.jboss.resteasy.resteasy-multipart-provider" />
<module name="org.jboss.resteasy.async-http-servlet-30" />
<module name="org.jboss.resteasy.resteasy-hibernatevalidator-provider" />
<module name="org.jboss.resteasy.resteasy-jettison-provider" />
<module name="org.jboss.resteasy.resteasy-spring" />
<module name="org.jboss.resteasy.resteasy-yaml-provider" />
</exclusions>
<dependencies>
</dependencies>
</deployment>
</jboss-deployment-structure>
This worked for me, Hope this will work for other

Unable to exclude logmanager module on JBoss 6 EAP

I'm trying to exclude all the logging modules from a jboss-deployment-structure.xml in JBoss 6 EAP.
My jboss-deployment-structure.xml is:
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
<module name="org.jboss.logging" />
<module name="org.jboss.logmanager" />
<module name="org.jboss.log4j.logmanager" />
</exclusions>
</deployment>
</jboss-deployment-structure>
So after I deploy my .war with said configuration I get:
[ModuleClassLoader for Module "org.jboss.log4j.logmanager:main" from local module loader #10ab323 (roots: /home/me/dev/jboss-eap-6.0/modules)] whereas object of type "org.apache.log4j.ConsoleAppender" was loaded by [ModuleClassLoader for Module "deployment.myapp.war:main" from Service Module Loader].
So I generally want to make JBoss stop trying to load log4j and let my application load it.
Is it at all possible to disable the logmanager module ?
Thanks,
I was able to resolve this problem using this jboss-deployment-structure.xml
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclusions>
<module name="org.apache.log4j"/>
<module name="org.apache.commons.logging"/>
</exclusions>
</deployment>
Which I have created under WEB-INF. You should also put your log4j.jar in WEB-INF/lib.

Categories

Resources