To force log4j to output where it's getting its logging settings from, add:
-Dlog4j.debug Log4j manual: http://logging.apache.org/log4j/docs/manual.html To log something with log4j do something like:
where e is an Exception and "blah" is a message you specify.
If you just callthen it will NOT log the stack trace.
Adding something like:will theoretically force log4j to use a particular log4j properties file. In practice it doesn't seem to actually work.
-Dlog4j.debug Log4j manual: http://logging.apache.org/log4j/docs/manual.html To log something with log4j do something like:
org.apache.log4j.Logger.getLogger(getClass()).error(""); org.apache.log4j.Logger.getLogger(getClass()).error("blah"); org.apache.log4j.Logger.getLogger(getClass()).error("",e); org.apache.log4j.Logger.getLogger(getClass()).error("blah",e);
org.apache.log4j.Logger.getLogger(getClass()).error(e);
-Dlogj4.configuration=file:/J:/resin/lib/log4j.properties\\
Forcing explicit initializing of log4j in webapp
Webapps sometimes fail to initialize log4j properly because log4j looks for the log4j.properties file after the app server is started but before the webapp is loaded. Here's a way to force it. Just call LoggingInit.doInit() in a static section of a globally used class. Of course, you could also add checking to ensure that multiple calls only do the loading once. That way you could call it from static sections of a a bunch of different code to ensure it's loaded.package com.something.snazzy; import java.io.IOException; import java.util.Properties; import org.apache.log4j.PropertyConfigurator; public class LoggingInit { public static void doInit() { try { Properties props = new Properties(); props.load( XferGateway.class.getResourceAsStream("../../../log4j.properties") ); PropertyConfigurator.configure(props); } catch(IOException e) { throw new RuntimeException(e); } } }
Version 6.1 last modified by Geoff Fortytwo on 11/07/2010 at 19:22
Document data
Attachments:
No attachments for this document