KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > common > log > SimpleLogger


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 common.Logger;
23
24 /**
25  * The default logger. Simple writes everything out to stdout or stderr
26  */

27 public class SimpleLogger extends Logger
28 {
29   /**
30    * Flag to indicate whether or not warnings should be suppressed
31    */

32   private boolean suppressWarnings;
33
34   /**
35    * Constructor
36    */

37   public SimpleLogger()
38   {
39     suppressWarnings = false;
40   }
41
42   /**
43    * Log a debug message
44    */

45   public void debug(Object JavaDoc message)
46   {
47     if (!suppressWarnings)
48     {
49       System.out.print("Debug: ");
50       System.out.println(message);
51     }
52   }
53
54   /**
55    * Log a debug message and exception
56    */

57   public void debug(Object JavaDoc message, Throwable JavaDoc t)
58   {
59     if (!suppressWarnings)
60     {
61       System.out.print("Debug: ");
62       System.out.println(message);
63       t.printStackTrace();
64     }
65   }
66
67   /**
68    * Log an error message
69    */

70   public void error(Object JavaDoc message)
71   {
72     System.err.print("Error: ");
73     System.err.println(message);
74   }
75
76   /**
77    * Log an error message object and exception
78    */

79   public void error(Object JavaDoc message, Throwable JavaDoc t)
80   {
81     System.err.print("Error: ");
82     System.err.println(message);
83     t.printStackTrace();
84   }
85
86   /**
87    * Log a fatal message
88    */

89   public void fatal(Object JavaDoc message)
90   {
91     System.err.print("Fatal: ");
92     System.err.println(message);
93   }
94
95   /**
96    * Log a fatal message and exception
97    */

98   public void fatal(Object JavaDoc message, Throwable JavaDoc t)
99   {
100     System.err.print("Fatal: ");
101     System.err.println(message);
102     t.printStackTrace();
103   }
104
105   /**
106    * Log an information message
107    */

108   public void info(Object JavaDoc message)
109   {
110     if (!suppressWarnings)
111     {
112       System.out.println(message);
113     }
114   }
115
116   /**
117    * Logs an information message and an exception
118    */

119
120   public void info(Object JavaDoc message, Throwable JavaDoc t)
121   {
122     if (!suppressWarnings)
123     {
124       System.out.println(message);
125       t.printStackTrace();
126     }
127   }
128
129   /**
130    * Log a warning message object
131    */

132   public void warn(Object JavaDoc message)
133   {
134     if (!suppressWarnings)
135     {
136       System.err.print("Warning: ");
137       System.err.println(message);
138     }
139   }
140
141   /**
142    * Log a warning message with exception
143    */

144   public void warn(Object JavaDoc message, Throwable JavaDoc t)
145   {
146     if (!suppressWarnings)
147     {
148       System.err.print("Warning: ");
149       System.err.println(message);
150       t.printStackTrace();
151     }
152   }
153
154   /**
155    * Accessor to the logger implementation
156    */

157   protected Logger getLoggerImpl(Class JavaDoc c)
158   {
159     return this;
160   }
161
162   /**
163    * Overrides the method in the base class to suppress warnings - it can
164    * be set using the system property jxl.nowarnings.
165    * This method was originally present in the WorkbookSettings bean,
166    * but has been moved to the logger class. This means it is now present
167    * when the JVM is initialized, and subsequent to change it on
168    * a Workbook by Workbook basis will prove fruitless
169    *
170    * @param w suppression flag
171    */

172   public void setSuppressWarnings(boolean w)
173   {
174     suppressWarnings = w;
175   }
176 }
177
Popular Tags