Use my log4j under jboss 6

I want to deploy my web application on JBOSS6. The application itself works, but registration does not work. I use log4j and added jboss-deployment-structure.xml to my war. Content

<jboss-deployment-structure> <deployment> <!-- Exclusions allow you to prevent the server from automatically adding some dependencies --> <exclusions> <module name="org.apache.log4j" /> <module name="org.jboss.logging" /> </exclusions> </deployment> 

In my log4j.xml I have

 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "dtd/log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> <appender name="LogAppender" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="C:\\logs\\web.log"/> <param name="MaxFileSize" value="10000KB"/> <param name="MaxBackupIndex" value="10"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%x %-5p [%d{yyyyMMdd HH:mm:ss}] - %c:%L - %m%n"/> </layout> </appender> <logger name="be.sofico.web"> <level value="debug" /> <appender-ref ref="LogAppender" /> </logger> 

All this works fine on tomcat and websphere (when I set the parent class to load by default)

How can I make it work on JBOSS 6?

+7
source share
3 answers

I solved my problem as follows: put jboss-deployment-structure.xml inside web \ META-INF with the following in the file

 <?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment> <exclusions> <module name="org.apache.log4j" /> <module name="org.apache.commons.logging" /> </exclusions> </deployment> </jboss-deployment-structure> 

And add this to the server startup: -Dorg.jboss.as.logging.per-deployment = false

+12
source

to set my log4j correctly in the classpath, I did 2 things:

1) I set the name log4j to use as follows

 -Dlog4j.configuration=fox-log4j.xml 

it should be in CLASSPATH

2) I call the registration manager explicitly, otherwise jboss log4j does not work

this gives in my run.conf:

 #parameter used by the JVM and call later in the log4j.xml LOG_FOLDER=$DIRNAME/../server/default/log #jvm options JAVA_OPTS="-Xms256m -Xmx4096m -XX:MaxPermSize=1024m -Dlog4j.configuration=fox-log4j.xml \ -Dfile.encoding=UTF-8 -Dfile.io.encoding=UTF-8 -DjavaEncoding=UTF-8 -Djboss.platform.mbeanserver \ -Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl \ -Djava.util.logging.manager=org.jboss.logmanager.LogManager \ -Dorg.jboss.logging.Logger.pluginClass=org.jboss.logging.logmanager.LoggerPluginImpl \ -DLOG_FOLDER=$LOG_FOLDER" 

now part of my log4j:

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"> <appender name="FOX_LOG" class="org.apache.log4j.RollingFileAppender"> <param name="Threshold" value="DEBUG"/> <param name="Append" value="true"/> <param name="MaxFileSize" value="25MB"/> <param name="MaxBackupIndex" value="5"/> <param name="File" value="${LOG_FOLDER}/fox.log"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{ISO8601} %-15x %t %-5p %-50.50c{1} - %m%n"/> </layout> </appender> <category name="com.mycompany" additivity="true"> <priority value="DEBUG"/> <appender-ref ref="FOX_LOG"/> </category> <root> <priority value="INFO"/> <appender-ref ref="FILE"/> </root> </log4j:configuration> 

hope this can help. considers

0
source

This means that it does not load your log4j.xml. Something is wrong with the location of the xml file or the problem with the class loader finding this log4j.xml.

-2
source

All Articles