JBoss 5.0.1: log4j.properties file not taking effect in EAR
I cannot get the settings in my log4j.properties file to take effect. I've already followed the advice in the following forum discussion:
http://community.jboss.org/message/198690#198690
Here is my log4j.properties file (in the root directory of the EAR):
#
# The root logger is set to INFO by default.
# This level can be changed programmatically at runtime.
#
log4j.rootLogger=INFO, stdout, file
# use the hibernate appender for audit logs.
log4j.logger.auditLogger.com.anfscd=INFO, hibernate, HBSS
# Console appender.
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p %d %c %x - %m %n
log4j.appender.stdout.Threshold=WARN
# Use this ConversionPattern to display thread.
#log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
# Daily rolling file appender.
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.File=c:/anfscd/log/anfscd-server.log
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.layout.ConversionPattern=%-5p %d %c %x - %m %n
# Use this ConversionPattern to display thread.
#log4j.appender.file.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
# Hibernate appender
log4j.appender.hibernate=com.anfscd.common.util.database.log.HibernateAppender
log4j.appender.hibernate.sessionServiceClass=com.anfscd.cmd.model.util.persistence.HibernateHelper
log4j.appender.hibernate.loggingEventClass=com.anfscd.cmd.model.audit.AuditLogRecord
# direct log messages 开发者_如何学运维to windows system logs #
log4j.appender.HBSS=org.apache.log4j.nt.NTEventLogAppender
log4j.appender.HBSS.Source=Project Name
log4j.appender.HBSS.layout=org.apache.log4j.PatternLayout
log4j.appender.HBSS.layout.ConversionPattern=%-5p %d %c %x - %m %n
# suppress org.hibernate messages
log4j.logger.org.hibernate=ERROR, stdout
Here is my jboss-app.xml (in [ear]/META-INF):
<?xml version="1.0" encoding="UTF-8"?>
<jboss-app>
<module-order>strict</module-order>
<loader-repository>
com.anfscd:loader=AnfscdLoader
<loader-repository-config>
java2ParentDelegation=false
</loader-repository-config>
</loader-repository>
</jboss-app>
We're using Hibernate for persistence, and it is quite verbose in the output console. I don't want to see Hibernate console output unless there's an error.
And by the way, I'm using log4j-1.2.15.jar.
Wow! Talk about chasing your tail!
First of all, bottom line, a Log4J running in JBoss 5.x does see and process a log4j.properties file in the root of an EAR.
... but only if there is nothing else to interfere with it. For instance, if you were to package a log4j.xml in the root of your EAR along with the log4j.properties, Log4J defaults to the .xml file over the .properties file. It loads the configuration from log4j.xml and doesn't even bother to look for a log4j.properties.
Alas, that particular scenario was not my problem.
When it was all said and done, my problem was a 3rd-party JAR that contained its own log4j.properties file. As with the .xml file, if Log4J stumbles across one log4j.properties, it does not bother to look for another one. Well, for whatever reason, in JBoss 4.2.x, Log4J took the log4j.properties in the root of the EAR over the one in the JAR. In contrast, in JBoss 5.x, Log4J took the log4j.properties file in the JAR rather than the one in the root of the EAR.
I have expunged the log4j.properties file from the 3rd-party JAR, and everything works like a charm.
I stumbled onto the cause of the problem by enabling Log4J's debug mode. FYI, you can do this by starting JBoss with the switch -Dlog4j.debug
or by setting debug="false"
in the log4j:configuration
tag in jboss-log4j.xml.
AFAIK is the root folder of the ear not added to the classpath and is the properties file as such invisible.
A better place would be in the root of a common jar file or in a WEB-INF/classes of the main war file.
精彩评论