X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Flog%2Flog4j%2FLoggerImpl.java;h=3d8adfbb707ea6b6638bfeb82a1c65790e4aa77c;hb=fa2ae3a41572f5b762b761935fc712b59c2a6933;hp=d821f5cc6b81388814ca90ebe56c6e95698513a1;hpb=5b2d2279e1d26546a38c5cd3ba3e4f72192e351b;p=mir.git diff --git a/source/mir/log/log4j/LoggerImpl.java b/source/mir/log/log4j/LoggerImpl.java index d821f5cc..3d8adfbb 100755 --- a/source/mir/log/log4j/LoggerImpl.java +++ b/source/mir/log/log4j/LoggerImpl.java @@ -1,63 +1,73 @@ -package mir.log.log4j; - -import org.apache.log4j.PropertyConfigurator; -import org.apache.log4j.Logger; - -import java.util.Map; -import java.util.HashMap; - -import mir.misc.MirConfig; - - -public class LoggerImpl implements mir.log.Logger { - - private static Map loggers = new HashMap(); - - public LoggerImpl() { - System.setProperty("log.home", MirConfig.getPropWithHome("Log.Home")); - PropertyConfigurator.configure(MirConfig.getPropWithHome("Log.log4j.ConfigurationFile").trim()); - } - - - public void debug( Object o, String s ) { - this.getLogger(o).debug(s); - } - - public void info( Object o, String s ) { - this.getLogger(o).info(s); - } - - public void warn( Object o, String s ) { - this.getLogger(o).warn(s); - } - - public void error( Object o, String s ) { - this.getLogger(o).error(s); - } - - public void fatal( Object o, String s ) { - this.getLogger(o).fatal(s); - } - - - private Logger getLogger( Object o ) { - String name; - - if (o instanceof String) { - name = (String) o; - } else if (o instanceof Class) { - name = ((Class)o).getName(); - } else if (o!=null) { - name = o.getClass().getName(); - } else { - name = "generic"; - } - - Logger l = (Logger)loggers.get(name); - if (l==null) { - l = Logger.getLogger(name); - loggers.put(name, l); - } - return l; - } +package mir.log.log4j; + +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; + +import org.apache.log4j.PropertyConfigurator; +import org.apache.log4j.Logger; + +import java.util.Map; +import java.util.HashMap; + + +public class LoggerImpl implements mir.log.Logger { + private static Map loggers = new HashMap(); + + public LoggerImpl() throws PropertiesConfigExc { + System.setProperty("log.home", + MirPropertiesConfiguration.instance().getStringWithHome("Log.Home")); + PropertyConfigurator.configure( + MirPropertiesConfiguration.instance().getStringWithHome("Log.log4j.ConfigurationFile").trim()); + } + + public void debug(Object o, String s) { + this.getLogger(o).debug(s); + } + + public void info(Object o, String s) { + this.getLogger(o).info(s); + } + + public void warn(Object o, String s) { + this.getLogger(o).warn(s); + } + + public void error(Object o, String s) { + this.getLogger(o).error(s); + } + + public void fatal(Object o, String s) { + this.getLogger(o).fatal(s); + } + + private Logger getLogger(Object o) { + String name; + Logger l; + + if (o instanceof String) { + name = (String) o; + } + else if (o instanceof Class) { + name = ( (Class) o).getName(); + } + else if (o != null) { + name = o.getClass().getName(); + } + else { + name = "generic"; + } + + synchronized (loggers) { + l = (Logger) loggers.get(name); + if (l == null) { + if (!loggers.containsKey(name)) { + l = Logger.getLogger(name); + loggers.put(name, l); + } + l = (Logger) loggers.get(name); + } + } + + return l; + } } \ No newline at end of file