-
1. Re: Embed Log4J in a war with AS 7.1.0
sewatech Feb 6, 2012 6:52 PM (in response to sewatech)I've found a solution, but I'm not sure it's the best one.
It looks like org.apache.log4j has been promoted to a system module, as it has the priority against my own jar, without declaring anything. So, to solve my problem, I decided to exclude the module from my deployment.
I added a WEB-INF/jboss-deployment-structure.xml file with the following content :
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
And now, it works, with my embedded log4j.xml file.
-
2. Re: Embed Log4J in a war with AS 7.1.0
prasad.deshpande Feb 7, 2012 11:39 AM (in response to sewatech)interesting... why do you need to specify exclusions? shouldn't application/war classloader use jar that comes with application first?
-
3. Re: Embed Log4J in a war with AS 7.1.0
markus78 Feb 7, 2012 12:05 PM (in response to prasad.deshpande)It should, but in the latest nightly builds it seems like the server does use the jboss module version unless an exclusion is used, I have a similar problem and it is pretty easy to test out, My problem https://community.jboss.org/thread/194889
-
4. Re: Embed Log4J in a war with AS 7.1.0
prasad.deshpande Feb 7, 2012 12:11 PM (in response to markus78)markus78 wrote:
I have a similar problem and it is pretty easy to test out, My problem https://community.jboss.org/thread/194889
Would you be able to attach a sample application to quickly test this problem?
-
5. Re: Embed Log4J in a war with AS 7.1.0
markus78 Feb 7, 2012 12:41 PM (in response to prasad.deshpande)Sure I can try, the EAR expects the log4j.properties.xml file directly in the root of "c:\"
Use latest nightly, and deploy ear then go to "localhost:8080/servletLog/hello" to invoke the servlet , then check the server log, the log4j message should be dumped to console and nothing is written to the file defined in the appenders in the specified log4j file.
/Markus
-
LogTest.ear 325.9 KB
-
log4j.properties.xml 720 bytes
-
-
6. Re: Embed Log4J in a war with AS 7.1.0
mackerman May 23, 2012 3:55 PM (in response to markus78)Just thought i'd point out that even with the approach mentioned here, it will not work if you are using commons-logging; it will not find the intended log4j module. You have to use log4j directly.
-
7. Re: Embed Log4J in a war with AS 7.1.0
jamezp May 23, 2012 4:45 PM (in response to mackerman)You could just exclude the servers version of commons-logging (org.apache.commons.logging) and include it in your deployment.
-
8. Re: Embed Log4J in a war with AS 7.1.0
remyvrs Jul 7, 2012 4:10 AM (in response to sewatech)Hello,
i found this thread, and some others that resemble this one.
i refer to loading the specific log4j settign from an ear
I still haven't managed to fix it , has anyone yet ?
-
9. Re: Embed Log4J in a war with AS 7.1.0
jamezp Jul 7, 2012 1:09 PM (in response to remyvrs)Maybe this will help you https://docs.jboss.org/author/display/AS71/How+To#HowTo-HowdoIuselog4j.propertiesorlog4j.xmlinsteadofusingtheloggingsubsystemconfiguration%3F. You mainly just need to exclude the servers library and include the log4j library in your deployment.
--
James R. Perkins
-
10. Re: Embed Log4J in a war with AS 7.1.0
remyvrs Jul 7, 2012 1:46 PM (in response to jamezp)thank, but that doesn't really help,
since i have already tried it and found other occurences that there is a bug in AS 7.1.1 so that you have to put in the deployment structure reference for all components loaded
BR,
Remus
-
11. Re: Embed Log4J in a war with AS 7.1.0
remyvrs Jul 8, 2012 4:56 AM (in response to remyvrs)Finally ,i have made it thru
it turns out that i forgot to mention i use slf4j, which also need to be excluded in order for it to use the binding to the log4j module from the ear/lib directory.
For anyone else that has a similar problem i recomend to remove the jar from the lib dir and make the jboss-deployment-structure file.
When you will have a good deployment structure your deployment will fail with ClassNotFound exception because exclusion of default modules will work and the jar will be missing, then you can add the jar file .
In my case org.apache.log4j was never missed since org.slf4j was loaded from "implicit modules dependency" ()
and it was already binded to the implicit module org.apache.log4j.
info used:
https://docs.jboss.org/author/display/AS7/How+do+I+migrate+my+application+from+AS5+or+AS6+to+AS7
https://docs.jboss.org/author/display/AS7/Implicit+module+dependencies+for+deployments
Thanks a lot for all your help,
Remus
-
12. Re: Embed Log4J in a war with AS 7.1.0
sewatech Sep 8, 2012 4:43 PM (in response to sewatech)Great news : this strange behaviour (bug ?) has been fixed in JBoss AS 7.1.2 (and in JBoss EAP 6).
-
13. Re: Embed Log4J in a war with AS 7.1.0
steljboss Dec 5, 2012 11:48 AM (in response to sewatech)It has? I still see it or it maybe something else I do wrong.
https://community.jboss.org/message/746799#746799
-
14. Re: Embed Log4J in a war with AS 7.1.0
sewatech Dec 5, 2012 11:54 AM (in response to steljboss)It's working on AS 7.1.2, the build-it-yourself version, and only with Log4J. When you put SLF4J in the game, you have to work around with jboss-deployment-structure.xml.