7

I want to deploy my web application on JBOSS6. The applicaation itself works, but the logging doens't. I use log4j and have added a jboss-deployment-structure.xml to my war. The contents are

<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>

This all works fine on tomcat and websphere (when I set classloading parent last)

How can I get it to work on JBOSS 6?

Vadzim
  • 24,954
  • 11
  • 143
  • 151
roel
  • 2,005
  • 3
  • 26
  • 41

3 Answers3

12

I solved my problem doing the following: 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 startup of the server: -Dorg.jboss.as.logging.per-deployment=false

roel
  • 2,005
  • 3
  • 26
  • 41
  • where do i need to add `-Dorg.jboss.as.logging.per-deployment=false`? what do you mean by startup of the server? which file do i need to change in JBoss ? – Mahantesh M Ambi Oct 15 '13 at 06:31
  • I mean, the script you use to start the server. In \bin\standalone.bat you will find something like rem Setup JBoss specific properties set JAVA_OPTS=-Dprogram.name=%PROGNAME% %JAVA_OPTS% You can add it there. – roel Oct 15 '13 at 10:59
  • Thanks roel for reply, I was starting my JBoss server from JBoss Administration console, and i added system property `-Dorg.jboss.as.logging.per-deployment` and set it to false. now it worked – Mahantesh M Ambi Oct 16 '13 at 06:44
  • 2
    Standalone.conf is probably a more suitable place to put such a change: http://stackoverflow.com/questions/12670415/log4j-doesnt-log-anything-under-jboss-6-eap – Paul R Rogers Nov 05 '13 at 19:35
  • 3
    Alternatively you can add system properties to your configuration xml file: – shonky linux user Aug 01 '14 at 00:33
0

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

1) I set the name of the log4j to use like this

-Dlog4j.configuration=fox-log4j.xml

this one has to be in the CLASSPATH

2) I call the logging manager explicitly otherwise the jboss log4j wont 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 a piece 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 could help. regards

  • Hi, I want to use org.apache.log4j and not the log4j provided with jboss. (I tried your solution, but it logs everything to server.log in stead of the file I configured) – roel Aug 27 '12 at 07:33
  • JBOSS logging service is ludicrously difficult to use. All we want is a simple file with some logs, not the server.log file but a one we choose, it shouldn't be so difficult to get ! – Tom Jan 23 '17 at 16:51
-2

It means it is not loading your log4j.xml. Something wrong with the xml file location or issue with the class loader finding this log4j.xml.