01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package mx4j.log;
10:
11: /**
12: * Log that redirects log calls to Jakarta Commons Logging. <p>
13: *
14: * @version $Revision: 1.3 $
15: */
16: public class CommonsLogger extends Logger {
17: private org.apache.commons.logging.Log log = null;
18:
19: public CommonsLogger() {
20: }
21:
22: protected void setCategory(String category) {
23: super .setCategory(category);
24: log = org.apache.commons.logging.LogFactory
25: .getLog(getCategory());
26: }
27:
28: protected void log(int priority, Object message, Throwable t) {
29: switch (priority) {
30: case Logger.FATAL:
31: if (t == null)
32: log.fatal(message);
33: else
34: log.fatal(message, t);
35: break;
36: case Logger.ERROR:
37: if (t == null)
38: log.error(message);
39: else
40: log.error(message, t);
41: break;
42: case Logger.WARN:
43: if (t == null)
44: log.warn(message);
45: else
46: log.warn(message, t);
47: break;
48: case Logger.INFO:
49: if (t == null)
50: log.info(message);
51: else
52: log.info(message, t);
53: break;
54: case Logger.DEBUG:
55: if (t == null)
56: log.debug(message);
57: else
58: log.debug(message, t);
59: break;
60: case Logger.TRACE:
61: if (t == null)
62: log.trace(message);
63: else
64: log.trace(message, t);
65: break;
66: }
67: }
68: }
|