Fabrizio Stellato
Fabrizio Stellato

Reputation: 1891

Jboss EAP 6.4 - configure slf4j-log4j12

I have the following pom.xml on my war:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>          
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <scope>provided</scope>
</dependency>       

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>          
    <scope>provided</scope>
</dependency>

and my log4j.properties is the following:

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Root logger option
log4j.rootLogger=DEBUG, stdout

# Hibernate logging options (INFO only shows startup messages)
log4j.logger.org.hibernate=INFO

# Log JDBC bind parameter runtime arguments
log4j.logger.org.hibernate.type=TRACE

The problem is that when I place log4j.properties inside src/main/resources, it doesn't print anything on console. If I delete log4j.properties from the directory above instead, it print info log.

What's going on ?

Upvotes: 1

Views: 2819

Answers (1)

DaImmi
DaImmi

Reputation: 131

EAP 6 has its own logging subsystem called JBoss LogManager and "encourages" you to use it by providing you with a mock .jar for log4j slf4j and some more logging frameworks. These mock .jars will be on your classpath at runtime. They basically forward all log messages to JBoss LogManager that is configured in the logging subsystem of your standalone.xml.

I actually like that approach as it unifies all the logging configuration in one place. Packaging your log4j.properties by the way will likely eliminate the option to change your logging configuration at runtime.

If you still want to use a real log4j though, you will have to do some work:

  • exclude the "fake" slf4j and log4j via jboss-deployment-structure.xml
  • package the real implementations instead (just change the maven scope from provided to compile)
  • stop JBoss LogManager from tinkering with your deplyment by setting the system property org.jboss.as.logging.per-deployment=false

Edit: The jboss-deployment-structure.xml might look like this:

<jboss-deployment-structure>
  <deployment>
    <exclusions>
      <module name="org.apache.log4j" />
      <module name="org.slf4j" />
    </exclusions>
  </deployment>
</jboss-deployment-structure>

If you have an ear you might also have to exclude these for every sub-deployment.

Upvotes: 4

Related Questions