- producer links are moved to an "advanced" page, not intended for normal
[mir.git] / source / mir / log / log4j / LoggerImpl.java
1 package mir.log.log4j;
2
3 import org.apache.log4j.PropertyConfigurator;
4 import org.apache.log4j.Logger;
5
6 import java.util.Map;
7 import java.util.HashMap;
8
9 import mir.misc.MirConfig;
10
11
12 public class LoggerImpl implements mir.log.Logger {
13
14     private static Map loggers = new HashMap();
15
16     public LoggerImpl() {
17       System.setProperty("log.home", MirConfig.getPropWithHome("Log.Home"));
18         PropertyConfigurator.configure(MirConfig.getPropWithHome("Log.log4j.ConfigurationFile").trim());
19     }
20
21
22     public void debug( Object o, String s ) {
23         this.getLogger(o).debug(s);
24     }
25
26     public void info( Object o, String s ) {
27         this.getLogger(o).info(s);
28     }
29
30     public void warn( Object o, String s ) {
31         this.getLogger(o).warn(s);
32     }
33
34     public void error( Object o, String s ) {
35         this.getLogger(o).error(s);
36     }
37
38     public void fatal( Object o, String s ) {
39         this.getLogger(o).fatal(s);
40     }
41
42
43     private Logger getLogger( Object o ) {
44         String name;
45
46         if (o instanceof String) {
47             name = (String) o;
48         } else if (o instanceof Class) {
49             name = ((Class)o).getName();
50         } else if (o!=null) {
51             name = o.getClass().getName();
52         } else {
53             name = "generic";
54         }
55
56         Logger l = (Logger)loggers.get(name);
57         if (l==null) {
58             l = Logger.getLogger(name);
59             loggers.put(name, l);
60         }
61         return l;
62     }
63 }