KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > log > impl > Log4jSimpleLogger


1 package jodd.log.impl;
2
3 import jodd.log.SimpleLogger;
4
5 import org.apache.log4j.Level;
6 import org.apache.log4j.Logger;
7 import org.apache.log4j.PropertyConfigurator;
8
9 /**
10  * Simple adapter for Log4J logger.
11  */

12 public class Log4jSimpleLogger implements SimpleLogger {
13
14     private static final String callerFQCN = Log4jSimpleLogger.class.getName();
15
16     // ---------------------------------------------------------------- logger
17

18     public static Log4jSimpleLogger getLogger(String loggerName) {
19         return new Log4jSimpleLogger(Logger.getLogger(loggerName));
20     }
21
22     public static Log4jSimpleLogger getLogger(Class clazz) {
23         return new Log4jSimpleLogger(Logger.getLogger(clazz));
24     }
25
26     private Logger log = null;
27
28     private Log4jSimpleLogger(Logger l) {
29         log = l;
30     }
31
32
33     // ---------------------------------------------------------------- configure
34

35     public static void configure(String configFile) {
36         PropertyConfigurator.configure(configFile);
37     }
38
39     // ---------------------------------------------------------------- interface
40

41     public void debug(Object message) {
42         log.log(callerFQCN, Level.DEBUG, message, null);
43     }
44     public void debug(Object message, Throwable t) {
45         log.log(callerFQCN, Level.DEBUG, message, t);
46     }
47
48     public void info(Object message) {
49         log.log(callerFQCN, Level.INFO, message, null);
50     }
51     public void info(Object message, Throwable t) {
52         log.log(callerFQCN, Level.INFO, message, t);
53     }
54
55     public void warn(Object message) {
56         log.log(callerFQCN, Level.WARN, message, null);
57     }
58     public void warn(Object message, Throwable t) {
59         log.log(callerFQCN, Level.WARN, message, t);
60     }
61
62     public void error(Object message) {
63         log.log(callerFQCN, Level.ERROR, message, null);
64     }
65     public void error(Object message, Throwable t) {
66         log.log(callerFQCN, Level.ERROR, message, t);
67     }
68
69     public void fatal(Object message) {
70         log.log(callerFQCN, Level.FATAL, message, null);
71     }
72     public void fatal(Object message, Throwable t) {
73         log.log(callerFQCN, Level.FATAL, message, t);
74     }
75
76 }
77
Popular Tags