Log4j not logging in with JBoss 6.1

I have a JavaEE application and am deploying it to JBoss 6.1. I want to 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 added this line to standalone.conf file

 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 do not see any logs on my console. Any idea?

+5
source share
3 answers

Make sure that $JAVA_OPTS is not overridden somewhere (to check it, you can put it directly in standalone.sh script just before initialization.

If the problem still persists, add the -Dlog4j.configuration property to specify the path to the configuration log file (make sure that you have the correct permission).

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

Be sure to configure the log4j.xml file .

Note that even if you define properties in a .conf file, they will be interpreted in a .sh file so that they are in a valid shell format, which means a space after = , for example, may be the main cause of your problem.

+2
source

since you are using slf4j-log4j12, we must also configure slf4j-log4j12 to add the following to the log properties.

  log4j.rootLogger=DEBUG, STDOUT log4j.logger.deng=INFO log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n 
0
source

Source: https://habr.com/ru/post/1212471/


All Articles