various fixes/cleanup: old producers are now completely gone, old logfile class too
[mir.git] / source / mir / log / log4j / LoggerImpl.java
index d821f5c..3d8adfb 100755 (executable)
@@ -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;\r
+\r
+import mir.config.MirPropertiesConfiguration;\r
+import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;\r
+\r
+import org.apache.log4j.PropertyConfigurator;\r
+import org.apache.log4j.Logger;\r
+\r
+import java.util.Map;\r
+import java.util.HashMap;\r
+\r
+\r
+public class LoggerImpl implements mir.log.Logger {\r
+  private static Map loggers = new HashMap();\r
+\r
+  public LoggerImpl() throws PropertiesConfigExc {\r
+    System.setProperty("log.home",\r
+        MirPropertiesConfiguration.instance().getStringWithHome("Log.Home"));\r
+    PropertyConfigurator.configure(\r
+        MirPropertiesConfiguration.instance().getStringWithHome("Log.log4j.ConfigurationFile").trim());\r
+  }\r
+\r
+  public void debug(Object o, String s) {\r
+    this.getLogger(o).debug(s);\r
+  }\r
+\r
+  public void info(Object o, String s) {\r
+    this.getLogger(o).info(s);\r
+  }\r
+\r
+  public void warn(Object o, String s) {\r
+    this.getLogger(o).warn(s);\r
+  }\r
+\r
+  public void error(Object o, String s) {\r
+    this.getLogger(o).error(s);\r
+  }\r
+\r
+  public void fatal(Object o, String s) {\r
+    this.getLogger(o).fatal(s);\r
+  }\r
+\r
+  private Logger getLogger(Object o) {\r
+    String name;\r
+    Logger l;\r
+\r
+    if (o instanceof String) {\r
+      name = (String) o;\r
+    }\r
+    else if (o instanceof Class) {\r
+      name = ( (Class) o).getName();\r
+    }\r
+    else if (o != null) {\r
+      name = o.getClass().getName();\r
+    }\r
+    else {\r
+      name = "generic";\r
+    }\r
+\r
+    synchronized (loggers) {\r
+      l = (Logger) loggers.get(name);\r
+      if (l == null) {\r
+        if (!loggers.containsKey(name)) {\r
+          l = Logger.getLogger(name);\r
+          loggers.put(name, l);\r
+        }\r
+        l = (Logger) loggers.get(name);\r
+      }\r
+    }\r
+\r
+    return l;\r
+  }\r
 }
\ No newline at end of file