Log4j不使用JBoss 6.1进行日志记录 [英] Log4j not logging with JBoss 6.1
问题描述
我有一个JavaEE应用程序,并且正在JBoss 6.1上部署它.我想使用Log4j.
I have a JavaEE application and I am deploying it on JBoss 6.1. I wanna use Log4j.
这些是我的依赖项:
<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>
这是我的log4j.properties
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
我已经在standalone.conf上添加了这一行
I have added this line on the standalone.conf
JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false"
这是我的jboss-deployment-structure.xml
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?
推荐答案
确保$JAVA_OPTS
没有在某处被覆盖(要进行测试,可以在初始化之前将其直接放在standalone.sh
脚本中.
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.
如果问题仍然存在,请添加-Dlog4j.configuration
属性以指定配置日志文件的路径(确保您具有正确的权限).
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"
确保您配置log4j.xml
文件.
Make sure you configure the log4j.xml
file.
请注意,即使您在.conf
文件中定义属性,它们也会在.sh
文件中解释,因此它们必须采用有效的shell格式,这意味着=
之后的空格可能是问题的根本原因.
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.
这篇关于Log4j不使用JBoss 6.1进行日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!