1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.jspf;
21
22 import org.apache.james.jspf.core.Logger;
23
24
25
26
27
28
29 public final class ConsoleLogger implements Logger {
30
31
32 public static final int LEVEL_DEBUG = 0;
33
34
35 public static final int LEVEL_INFO = 1;
36
37
38 public static final int LEVEL_WARN = 2;
39
40
41 public static final int LEVEL_ERROR = 3;
42
43
44 public static final int LEVEL_FATAL = 4;
45
46
47 public static final int LEVEL_DISABLED = 5;
48
49 private final int m_logLevel;
50
51
52
53
54 private String m_path;
55
56
57
58
59 public ConsoleLogger()
60 {
61 this( LEVEL_DEBUG , "ROOT");
62 }
63
64
65
66
67
68 public ConsoleLogger( final int logLevel, final String path )
69 {
70 m_logLevel = logLevel;
71 m_path = path;
72 }
73
74
75
76
77
78
79 public void debug( final String message )
80 {
81 debug( message, null );
82 }
83
84
85
86
87
88
89
90 public void debug( final String message, final Throwable throwable )
91 {
92 if( m_logLevel <= LEVEL_DEBUG )
93 {
94 System.out.print( "[DEBUG] " );
95 System.out.print( m_path+" " );
96 System.out.println( message );
97
98 if( null != throwable )
99 {
100 throwable.printStackTrace( System.out );
101 }
102 }
103 }
104
105
106
107
108
109
110 public boolean isDebugEnabled()
111 {
112 return m_logLevel <= LEVEL_DEBUG;
113 }
114
115
116
117
118
119
120 public void info( final String message )
121 {
122 info( message, null );
123 }
124
125
126
127
128
129
130
131 public void info( final String message, final Throwable throwable )
132 {
133 if( m_logLevel <= LEVEL_INFO )
134 {
135 System.out.print( "[INFO] " );
136 System.out.print( m_path+" " );
137 System.out.println( message );
138
139 if( null != throwable )
140 {
141 throwable.printStackTrace( System.out );
142 }
143 }
144 }
145
146
147
148
149
150
151 public boolean isInfoEnabled()
152 {
153 return m_logLevel <= LEVEL_INFO;
154 }
155
156
157
158
159
160
161 public void warn( final String message )
162 {
163 warn( message, null );
164 }
165
166
167
168
169
170
171
172 public void warn( final String message, final Throwable throwable )
173 {
174 if( m_logLevel <= LEVEL_WARN )
175 {
176 System.out.print( "[WARNING] " );
177 System.out.print( m_path+" " );
178 System.out.println( message );
179
180 if( null != throwable )
181 {
182 throwable.printStackTrace( System.out );
183 }
184 }
185 }
186
187
188
189
190
191
192 public boolean isWarnEnabled()
193 {
194 return m_logLevel <= LEVEL_WARN;
195 }
196
197
198
199
200
201
202 public void error( final String message )
203 {
204 error( message, null );
205 }
206
207
208
209
210
211
212
213 public void error( final String message, final Throwable throwable )
214 {
215 if( m_logLevel <= LEVEL_ERROR )
216 {
217 System.out.print( "[ERROR] " );
218 System.out.print( m_path+" " );
219 System.out.println( message );
220
221 if( null != throwable )
222 {
223 throwable.printStackTrace( System.out );
224 }
225 }
226 }
227
228
229
230
231
232
233 public boolean isErrorEnabled()
234 {
235 return m_logLevel <= LEVEL_ERROR;
236 }
237
238
239
240
241
242
243 public void fatalError( final String message )
244 {
245 fatalError( message, null );
246 }
247
248
249
250
251
252
253
254 public void fatalError( final String message, final Throwable throwable )
255 {
256 if( m_logLevel <= LEVEL_FATAL )
257 {
258 System.out.print( "[FATAL ERROR] " );
259 System.out.print( m_path+" " );
260 System.out.println( message );
261
262 if( null != throwable )
263 {
264 throwable.printStackTrace( System.out );
265 }
266 }
267 }
268
269
270
271
272
273
274 public boolean isFatalErrorEnabled()
275 {
276 return m_logLevel <= LEVEL_FATAL;
277 }
278
279
280
281
282
283
284
285 public Logger getChildLogger( final String name )
286 {
287 return new ConsoleLogger(m_logLevel, m_path+"."+name);
288 }
289 }