01: package org.enhydra.dm.loggers;
02:
03: import org.apache.log4j.Level;
04: import org.apache.log4j.Logger;
05: import org.enhydra.dm.api.loggers.Log;
06:
07: /**
08: * Log4j extension for abstract Log class.
09: *
10: * @author Slobodan Vujasinovic
11: */
12:
13: public class Log4jLog extends Log {
14:
15: private Logger logger = null;
16:
17: protected void logMessage(int level, String message) {
18: Level lev;
19:
20: if (logger == null) {
21: logger = Logger.getLogger("EnhydraDM");
22: }
23: lev = intToLevel(level);
24: if (lev == null) {
25: lev = Level.INFO;
26: }
27: logger.log(lev, message);
28:
29: }
30:
31: private Level intToLevel(int level) {
32: Level lev;
33:
34: switch (level) {
35: case CRITICAL:
36: case ERROR:
37: lev = Level.ERROR;
38: break;
39:
40: case WARNING:
41: lev = Level.WARN;
42: break;
43:
44: case INFORMATION:
45: lev = Level.INFO;
46: break;
47:
48: case DEBUG:
49: lev = Level.DEBUG;
50: break;
51:
52: default:
53: lev = Level.DEBUG;
54: }
55: return lev;
56: }
57:
58: }
|