JBoss, log4j and EBJ 2
wgpuckett Feb 4, 2011 3:47 PMI am really struggling with getting my logging working. I have a mature web application that has been in production for about 4 years. It runs in JBoss 4.3.3.GA using Java v1.6. The application is developed using EJB 2 and Struts. My development environment is MyEclipse IDE with the enterprise capability turned on. I am using log4j for all my logs. I am using v1.2.13 of log4j. I have the application deployed in the default server of JBoss. So I put the ear file in d:\jboss\server\default\deploy and the log4j.jar file in d:\jboss\server\deploy\lib.
At first I could get all my log messages out but it was always mixed in with the normal jboss messages. Eventually I developed my own process of logging using log4j. I'll provide details below. Essentially I am now at a point where I have discovered that any logging that comes out of the EJB project doesn't go to a log file. I have entered debug mode and followed the code. It shows that debug mode is one and the message is generated but I can't find it in any of the application OR JBoss log files. In my action classes in the WEB project I include code from the EJB project. I get the debug messages from the WEB code but not the EJB code.
It's driving me crazy!!
Here is my log4j properties file:
log4j.rootLogger=ERROR, console log4j.category.MyApp=DEBUG, applog ********************************************** * applog is a DailyRollingFileAppender * ********************************************** log4j.appender.applog=org.jboss.logging.appender.DailyRollingFileAppender log4j.appender.applog.file=D:/MyApp/logs/web.log log4j.appender.applog.datePattern='.'yyyy-MM-dd'.log' log4j.appender.applog.append=true log4j.appender.applog.threshold=DEBUG log4j.appender.applog.immediateFlush=true log4j.appender.applog.layout=org.apache.log4j.PatternLayout log4j.appender.applog.layout.ConversionPattern=%-5p %d{ISO8601} [%t] %C{1}::%M:%L %m%n ********************************************** * console for everything else * ********************************************** log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.Threshold=ERROR log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=%d %5p %c (%F:%L) – %m%n ********************************************* * Now set up the thresholds by class * ********************************************* log4j.logger.MyApp.com=DEBUG log4j.logger.MyApp.mm=DEBUG
I have custom code that accesses the configuration. I call it WebLogger
package com.myapp.common.logger; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.Properties; import com.myapp.common.exception.*; public class WebLogger { private WebLogger() { } public static Logger getLogger(Class tCls) throws ErrorException { return getLogger(tCls.getName()); } public static Logger getLogger(String tLvl) throws ErrorException { Logger rtn = Logger.getLogger(tLvl); if(rtn.getParent().getName().equals("root")) { initLogger(); rtn = Logger.getLogger(tLvl); } return rtn; } private static void initLogger() throws ErrorException { System.setProperty("log4j.defaultInitOverride", "true"); ClassLoader cl = WebLogger.class.getClassLoader(); String appHome = System.getenv("MYAPP_HOME"); try { File fIn = new File(appHome+"\\lib", "log4j.properties"); if(fIn.exists()) { InputStream is = new FileInputStream(fIn); cl.loadClass("org.apache.log4j.PropertyConfigurator"); Properties p = new Properties(); p.load(is); PropertyConfigurator.configure(p); } } catch (Exception e) { throw new ErrorException("Unable to initialize the logger. Error msg is: "+e.getMessage()); } } }
In my code I initialize the logger as: (APP_PKG contains "MyApp.")
Logger logger = com.myapp.common.logger.WebLogger.getLogger(APP_PKG + MyClass.class.getName());
All of the ejb packages start with mm.myapp. None of the web packages start with that.
Again, the log messages from the web container is going Where is the output from my code going?