我在java应用程序中使用常见的日志记录和jboss eap 6.2,日志文件正在创建但是空的并且hibernate日志也无法正常工作。
这是我的jboss-deployment-structure.xml
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.commons.logging"/>
<module name="org.apache.log4j"/>
</exclusions>
</deployment>
<sub-deployment name="abc.war">
<exclusions>
<module name="org.apache.log4j"/>
<module name="org.apache.commons.logging"/>
</exclusions>
</sub-deployment>
</jboss-deployment-structure>
这是我的log4j.properties
log4j.rootLogger=DEBUG, FILE
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=c\:\\log\\eSocietySQLLog.log
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.Threshold=debug
log4j.appender.FILE.Append=true
log4j.appender.FILE.MaxFileSize=10MB
log4j.appender.FILE.MaxBackupIndex=5
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %c %n%m%C
log4j.appender.FILE.DatePattern='.' yyyy-MM-dd-a
并在jboss eap 6.2的standalone.conf中添加JAVA_OPTS =“$ JAVA_OPTS -Dorg.jboss.as.logging.per-deployment = false”。
答案 0 :(得分:6)
我得到了答案,我的log4j正在运行。
1)我在jboss eap 6.2 GA jboss_home/modules/com
模块为log4j/mylog4j/main
推出了module.xml
文件和log4j-1.2.16.jar
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.fourthdti.esociety">
<resources>
<resource-root path="log4j-1.2.16.jar"/>
</resources>
<dependencies>
<module name="org.apache.log4j"/>
<module name="javax.api"/>
</dependencies>
</module>
2)在standalone.conf
JBOSS_HOME/bin
添加单行代码
JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.as.logging.per-deployment=false"
3)在jboss-deployment-structure.xml
耳朵
META_INF
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<deployment name="eSociety-ear.ear">
<dependencies>
<module name="com.log4j.mylog4j" export="true" />
</dependencies>
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
<module name="org.slf4j" />
<module name="org.jboss.logging" />
<module name="org.antlr"/>
<module name="org.hibernate.*"/>
</exclusions>
</deployment>
<sub-deployment name="abc-ejb-0.0.1-SNAPSHOT.jar">
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
<module name="org.slf4j" />
<module name="org.jboss.logging" />
<module name="org.antlr"/>
<module name="org.hibernate.*"/>
</exclusions>
</sub-deployment>
<sub-deployment name="abc-web-0.0.1-SNAPSHOT.war">
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
<module name="org.slf4j" />
<module name="org.jboss.logging" />
<module name="org.antlr"/>
<module name="org.hibernate.*"/>
</exclusions>
</sub-deployment>
</jboss-deployment-structure>
4)在我的课程路径中提出log4j.properties
log4j.rootLogger=DEBUG, FILE, stdout
log4j.logger.org.hibernate=debug
log4j.logger.org.springframework=debug
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.SQL=trace
log4j.logger.org.hibernate.type= trace
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug
#log4j.logger.org.hibernate.jdbc=trace
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
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=c\:\\log\\eSociety.log
log4j.appender.FILE.ImmediateFlush=true
log4j.appender.FILE.Threshold=debug
log4j.appender.FILE.Append=true
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c - %m%n
log4j.appender.FILE.MaxFileSize=10MB
log4j.appender.FILE.MaxBackupIndex=2
5)在pom.xml
<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配置来说已经足够了。