Hi all, I'm having an odd little problem here...
I have a webapp where I use Log4J underneath JCL. I use an XML config file and Log4J is initialized in a ServletContextListener. The code in the listener does some hackery on the XML... basically, I construct a real path to my log files on the fly, update the XML and then configure logging using the updated XML. Now, before anyone tells me how there are 10 other and clearly better ways to do that (I have no doubt there are), the bottom line is that this works and has worked for over a year. I've moved it between Tomcat (on both Windows and Linux) and Websphere (and earlier version) with no issue. The problem now though is that I'm deploying it on a newer Websphere (5.1.1) on Windows... what's happening is that the log files are created and are locked (i.e., I can't delete them), and they are where they are supposed to be (a logs directory under my webapp), so everything SEEMS to be starting up fine and as expected. However, no messages are making it to the log files. They are showing up in Websphere's stdout and stderr logs instead. So, I'm not sure this is a Log4J problem or strictly a Websphere issue, but I'm hoping someone has seem a similar issue and can shed some light on it. I'm not seeing any messages indicating problems anywhere, for all intents and purposes it appears like it should be working just fine. Note that this very same code runs perfectly as you see it below (I did remove spaces and comments to shorten the post though) under Tomcat, so it truly is something Websphere-related, but whether I can configure Log4J in some different way or not to overcome it is what I don't know. Here's my config file: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> <param name="Threshold" value="DEBUG"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5p %l %x- %m\n" /> </layout> </appender> <appender name="TOAINFOFILE" class="org.apache.log4j.FileAppender"> <param name="Threshold" value="DEBUG"/> <param name="File" value="c:\\tomcat\\webapps\\toa\\logs\\toaInfo.log"/> <param name="Append" value="false"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5p %l %x- %m\n" /> </layout> </appender> <appender name="TOAERRORFILE" class="org.apache.log4j.FileAppender"> <param name="Threshold" value="ERROR"/> <param name="File" value="c:\\tomcat\\webapps\\toa\\logs\\toaError.log"/> <param name="Append" value="false"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5p %l %x- %m\n" /> </layout> </appender> <appender name="TOAAGINGFILE" class="org.apache.log4j.FileAppender"> <param name="Threshold" value="DEBUG"/> <param name="File" value="c:\\tomcat\\webapps\\toa\\logs\\toaAging.log"/> <param name="Append" value="false"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5p %l %x- %m\n" /> </layout> </appender> <category name="com.company" additivity="true"> <appender-ref ref="CONSOLE" /> <appender-ref ref="TOAINFOFILE" /> <appender-ref ref="TOAERRORFILE" /> </category> <category name="com.company.toa.daemonthreads.AgingProcessDaemonThread" additivity="true"> <appender-ref ref="TOAAGINGFILE" /> </category> </log4j:configuration> And here's my ContextListener: import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileReader; import java.io.InputStream; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.LogManager; import org.apache.log4j.xml.DOMConfigurator; public class TOAServletContextListener implements ServletContextListener { public void contextInitialized(ServletContextEvent sce) { System.out.println(this.getClass().getName() + " - Initializing Logging..."); try { ServletContext sc = sce.getServletContext(); String lConfigFile = sc.getRealPath("/WEB-INF/loggingConfig.xml"); lPath += File.separator; lPath = TOAHelpers.strReplace(lPath, "\\", "\\\\"); FileReader fr = new FileReader(lConfigFile); BufferedReader br = new BufferedReader(fr); StringBuffer sbXML = new StringBuffer(); String line = ""; while ((line = br.readLine()) != null) { sbXML.append(line); } br.close(); String xml = sbXML.toString(); xml = TOAHelpers.strReplace(xml, "<param name=\"File\" value=\"", "<param name=\"File\" value=\"" + lPath); InputStream isXML = new ByteArrayInputStream(xml.getBytes()); new DOMConfigurator().doConfigure(isXML, LogManager.getLoggerRepository()); Log log = LogFactory.getLog(getClass()); log.info("Log4J initialized"); } catch (Exception e) { System.err.println("Exception in TOAServletContextListener(): " + e); } } public void contextDestroyed(ServletContextEvent sce) { } } Thanks in advance! -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
