[slf4j-user] Per-web-app logging with jars on the ser ver's classpath

Mark Stralka mstralka at gmail.com
Thu Mar 22 12:19:52 CET 2007


Ceki Gülcü <listid <at> qos.ch> writes:

> 
> Hi Mark,
> 
> I don't see how implementing o.a.c.logging.Log and LogFactory with log4j 
> helps around this problem. How do you avoid keeping a map of JCL adapters 
> wrapping log4j loggers? If you don't keep a map, how do you avoid building 
> a new JCL adapter object each time the LogFactory.getFactory gets called?
> 
> Does the above make sense?
> 

Hi Ceki,

In my custom MyFrameworkLogFactory.getInstance(String name) method I do the
following:

Context ctx = null;
String loggingContextName = null;
String fullName = null;
try {
	ctx = JNDIUtil.getInitialContext();
	loggingContextName = (String) JNDIUtil.lookup(ctx, Constants.JNDI_CONTEXT_NAME);
} catch (NamingException ne) {
	// we can't log here
	ne.printStackTrace();
}

fullName = loggingContextName + "-" + name;

synchronized (this) {
	instance = (Log) loggerMap.get(fullName);
	if (instance == null) {
		Logger logger = Logger.getLogger(name);
		instance = new HpLog(logger);
		loggerMap.put(fullName, instance);
	}
}
return instance;

Is that wrong or inefficient?




More information about the slf4j-user mailing list