KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > common > log > Log4JLogger


1 /*********************************************************************
2 *
3 * Copyright (C) 2003 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package common.log;
21
22 import org.apache.log4j.Logger;
23
24 /**
25  * A logger which uses the log4j library from jakarta. Each instance
26  * of this class acts as a wrapper to the log4j Logger class
27  */

28 public class Log4JLogger extends common.Logger
29 {
30   /**
31    * The log4j logger
32    */

33   private Logger log4jLogger;
34
35   /**
36    * Default constructor. This constructor is
37    */

38   public Log4JLogger()
39   {
40     super();
41   }
42
43   /**
44    * Constructor invoked by the getLoggerImpl method to return a logger
45    * for a particular class
46    */

47   private Log4JLogger(Logger l)
48   {
49     super();
50     log4jLogger = l;
51   }
52
53   /**
54    * Log a debug message
55    */

56   public void debug(Object JavaDoc message)
57   {
58     log4jLogger.debug(message);
59   }
60
61   /**
62    * Log a debug message and exception
63    */

64   public void debug(Object JavaDoc message, Throwable JavaDoc t)
65   {
66     log4jLogger.debug(message, t);
67   }
68
69   /**
70    * Log an error message
71    */

72   public void error(Object JavaDoc message)
73   {
74     log4jLogger.error(message);
75   }
76
77   /**
78    * Log an error message object and exception
79    */

80   public void error(Object JavaDoc message, Throwable JavaDoc t)
81   {
82     log4jLogger.error(message, t);
83   }
84
85   /**
86    * Log a fatal message
87    */

88   public void fatal(Object JavaDoc message)
89   {
90     log4jLogger.fatal(message);
91   }
92
93   /**
94    * Log a fatal message and exception
95    */

96   public void fatal(Object JavaDoc message, Throwable JavaDoc t)
97   {
98     log4jLogger.fatal(message,t);
99   }
100
101   /**
102    * Log an information message
103    */

104   public void info(Object JavaDoc message)
105   {
106     log4jLogger.info(message);
107   }
108
109   /**
110    * Logs an information message and an exception
111    */

112
113   public void info(Object JavaDoc message, Throwable JavaDoc t)
114   {
115     log4jLogger.info(message, t);
116   }
117
118   /**
119    * Log a warning message object
120    */

121   public void warn(Object JavaDoc message)
122   {
123     log4jLogger.warn(message);
124   }
125
126   /**
127    * Log a warning message with exception
128    */

129   public void warn(Object JavaDoc message, Throwable JavaDoc t)
130   {
131     log4jLogger.warn(message, t);
132   }
133
134   /**
135    * Accessor to the logger implementation
136    */

137   protected common.Logger getLoggerImpl(Class JavaDoc cl)
138   {
139     Logger l = Logger.getLogger(cl);
140     return new Log4JLogger(l);
141   }
142 }
143
Popular Tags