Mohan
Mohan

Reputation: 741

JBoss AS 7.1.1 Final and Log4j + Not working

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)

Upvotes: 1

Views: 2280

Answers (2)

newohybat
newohybat

Reputation: 186

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>  

Upvotes: 0

Ricardo Vila
Ricardo Vila

Reputation: 1632

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.

Upvotes: 1

Related Questions