To force log4j to output where it's getting its logging settings from, add:

Log4j manual:

To log something with log4j do something like:

where e is an Exception and "blah" is a message you specify.

If you just call

then 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.

Forcing explicit initializing of log4j in webapp

Webapps sometimes fail to initialize log4j properly because log4j looks for the 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.util.Properties;
import org.apache.log4j.PropertyConfigurator;

public class LoggingInit
	public static void doInit() {
		try {
			Properties props = new Properties();
			props.load( XferGateway.class.getResourceAsStream("../../../") );
		} catch(IOException e) {
			throw new RuntimeException(e);
Version 6.1 last modified by Geoff Fortytwo on 11/07/2010 at 19:22

Attachments 0

No attachments for this document
Website Top
Send Me Mail!:
   g42website4 AT
My Encyclopaedia Blog

Creator: Geoff Fortytwo on 2008/05/12 01:16
Copyright 2004-2007 (c) XPertNet and Contributing Authors