How to setup log4j in JBoss AS7
davidj Nov 15, 2012 1:49 PMHi,
Can someone step me thru how to setup log4j on JBoss AS7?
I want the easiest way possible (not some fancy solution which requires me to modify all sorts of JBoss configuration and module files/directories).
I've tried the following.
I have an EJB Jar file which has a "log4j.properties" file. This file has the usual stuff in it.... nothing fancy, just the same old stuff you always put in this file. In-fact, I'll past it below:
log4j.rootLogger=TRACE, stdout, R
# Define stdout appender
# =============================================
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d{MM-dd-yyyy hh:mm:ss}] [%c] [%-5p] %m%n
#Define R appender
# =============================================
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=myLogger.log
log4j.appender.R.MaxFileSize=9216KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[%d{MMM-dd hh:mm:ss}] [%c{1}] %m%n
This file is located in my "src/main/resources" folder (just like it should be since this is a Maven project)
This same JAR file will log correctly on other AppServers (such as Glassfish).
Will not work on JBoss AS7 (it will not log anything; it won't even create a "myLogger.log" file).
I read else where that I must do the following in my "standalone.xml" file:
<size-rotating-file-handler name="MY_LOGGER">
<level name="TRACE"/>
<formatter>
<pattern-formatter pattern="%d{MMM-dd hh:mm:ss} [%c{1}] %m%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="myLogger.log"/>
<rotate-size value="9216K"/>
<max-backup-index value="3"/>
</size-rotating-file-handler>
<logger category="com.mycompany">
<level name="TRACE"/>
<handlers>
<handler name="MY_LOGGER"/>
</handlers>
</logger>
I tried that and it still doesn't work
Any help would be appreciated. Thanks.
As a side note, the JAR is actually placed inside of an EAR file, and the EAR file is what actually gets deployed to JBoss. I'm not sure if this make a difference.