KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > log > CommonsLogger


1 /*
2  * Copyright (C) MX4J.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.log;
10
11 /**
12  * Log that redirects log calls to Jakarta Commons Logging. <p>
13  *
14  * @author <a HREF="mailto:warrenm@users.sourceforge.net">Warren Mira</a>
15  * @version $Revision: 1.1 $
16  */

17 public class CommonsLogger extends Logger
18 {
19    private org.apache.commons.logging.Log log = null;
20
21    public CommonsLogger()
22    {
23    }
24
25    protected void setCategory(String JavaDoc category)
26    {
27       super.setCategory(category);
28       log = org.apache.commons.logging.LogFactory.getLog(getCategory());
29    }
30
31    protected void log(int priority, Object JavaDoc message, Throwable JavaDoc t)
32    {
33       switch (priority)
34       {
35          case Logger.FATAL:
36             if (t == null)
37                log.fatal(message);
38             else
39                log.fatal(message, t);
40             break;
41          case Logger.ERROR:
42             if (t == null)
43                log.error(message);
44             else
45                log.error(message, t);
46             break;
47          case Logger.WARN:
48             if (t == null)
49                log.warn(message);
50             else
51                log.warn(message, t);
52             break;
53          case Logger.INFO:
54             if (t == null)
55                log.info(message);
56             else
57                log.info(message, t);
58             break;
59          case Logger.DEBUG:
60             if (t == null)
61                log.debug(message);
62             else
63                log.debug(message, t);
64             break;
65          case Logger.TRACE:
66             if (t == null)
67                log.trace(message);
68             else
69                log.trace(message, t);
70             break;
71       }
72    }
73 }
74
Popular Tags