Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j not logging with JBoss 6.1

I have a JavaEE application and I am deploying it on JBoss 6.1. I wanna use Log4j.

These are my dependencies:

<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.1</version>
</dependency>

<dependency>
        <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.5.10</version>
</dependency>

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.16</version>
</dependency>

<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.4</version>
</dependency>

This is my log4j.properties

log4j.rootLogger=info, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{${datestamp}} %5p: %c{2} - %m%n

I have added this line on the standalone.conf

JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false"

This is my jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>

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

I can see no logs on my console. Any idea?

like image 374
Elsban Avatar asked Feb 02 '15 20:02

Elsban


People also ask

Does JBoss logging use log4j?

JBoss AS uses log4j as logging framework. This tutorial will show how to configure log4j service in your jBoss application server and also how to create a custom configuration which can be deployed along with your application. Log4j is a flexible open source project from Apache.

What are the logging levels in JBoss?

By default, JBoss produces output to both the console and a log file ( log/server. log ). There are six basic log levels in log4j: TRACE , DEBUG , INFO , WARN , ERROR and FATAL .


1 Answers

Make sure the $JAVA_OPTS is not overridden somewhere (to test it you could put it directly in the standalone.sh script just before the initialization.

If the problem still persist, then add the -Dlog4j.configuration property to specify the path to the configuration log file (make sure you have the right permission).

JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false -Dlog4j.configuration=file:$JBOSS_HOME/standalone/configuration/log4j.xml"

Make sure you configure the log4j.xml file.

Note that even if you define the properties in the .conf file, they will be interpreted in the .sh file so they must be in valid shell format which mean a space after an = for example could be the root cause of your problem.

like image 163
Jean-François Savard Avatar answered Oct 26 '22 21:10

Jean-François Savard