> import org.apache.tools.log4j.Category; > > public class LoggerFactory { > > private static boolean configured = false; > > private static void configure() { > if (!configured) { > /*** Place all your configuration stuff here. ***/ > configured = true; > } > } > > public static Category getInstance(Class c) { > configure(); > return Category.getInstance(c); > } > > public static Category getInstance(String s) { > configure(); > return Category.getInstance(s); > } > > }
This isn't thread-safe, because if two threads call getInstance() at the same time, your configure code could run twice. A slightly better solution would be to use synchronized to make sure it's thread safe. This is technically against the J2EE spec. Here it is anyway: private static void configure() { if(!configured) { synchronized(LoggerFactory.class) { if(!configured) { /** Do config */ configured = true; } } } } Note the double-check of the configured boolean. Having said all that, running config code twice probably isn't the end of the world, and might not happen very often. Regards, Mike. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]