1 package org.apache.turbine.services.logging;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache Turbine" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * "Apache Turbine", nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 import java.io.PrintWriter;
58 import java.io.StringWriter;
59 import org.apache.turbine.services.TurbineServices;
60
61 /***
62 * An adapter for integrating external code (e.g., J2EE) that expects a simple
63 * PrintWriter for logging.
64 *
65 * @author <a href="mailto:chrise@scardini.com">Christopher Elkins</a>
66 * @version $Id: LogWriter.java,v 1.1.1.1 2001/08/16 05:09:03 jvanzyl Exp $
67 */
68 public class LogWriter extends PrintWriter
69 {
70 private LoggingService logger;
71
72 /***
73 * Default constructor.
74 */
75 public LogWriter()
76 {
77 // We don't care what the parent class is doing. This class would
78 // seem a lot less silly if PrintWriter were an interface. Oh, well.
79 super(new StringWriter());
80
81 logger = (LoggingService)TurbineServices.getInstance()
82 .getService(LoggingService.SERVICE_NAME);
83 }
84
85 /***
86 * Logs the specified message.
87 */
88 private void log(String message)
89 {
90 logger.info(message);
91 }
92
93 /***
94 * Flush the stream.
95 */
96 public void flush()
97 {
98 // do nothing
99 }
100
101 /***
102 * Close the stream.
103 */
104 public void close()
105 {
106 logger.shutdown();
107 }
108
109 /***
110 * Flush the stream and check its error state.
111 */
112 public boolean checkError()
113 {
114 // false indicates lack of error
115 return false;
116 }
117
118 /***
119 * Write a single character.
120 */
121 public void write(int c)
122 {
123 log(String.valueOf(c));
124 }
125
126 /***
127 * Write a portion of an array of characters.
128 */
129 public void write(char buf[], int off, int len)
130 {
131 log(String.valueOf(buf, off, len));
132 }
133
134 /***
135 * Write an array of characters.
136 */
137 public void write(char buf[])
138 {
139 log(String.valueOf(buf));
140 }
141
142 /***
143 * Write a portion of a string.
144 */
145 public void write(String s, int off, int len)
146 {
147 log(s.substring(off, off + len));
148 }
149
150 /***
151 * Write a string.
152 */
153 public void write(String s)
154 {
155 log(s);
156 }
157
158 /***
159 * Print a boolean.
160 */
161 public void print(boolean b)
162 {
163 log(String.valueOf(b));
164 }
165
166 /***
167 * Print a character.
168 */
169 public void print(char c)
170 {
171 log(String.valueOf(c));
172 }
173
174 /***
175 * Print an integer.
176 */
177 public void print(int i)
178 {
179 log(String.valueOf(i));
180 }
181
182 /***
183 * Print a long integer.
184 */
185 public void print(long l)
186 {
187 log(String.valueOf(l));
188 }
189
190 /***
191 * Print a floating-point number.
192 */
193 public void print(float f)
194 {
195 log(String.valueOf(f));
196 }
197
198 /***
199 * Print a double-precision floating-point number.
200 */
201 public void print(double d)
202 {
203 log(String.valueOf(d));
204 }
205
206 /***
207 * Print an array of characters.
208 */
209 public void print(char s[])
210 {
211 log(String.valueOf(s));
212 }
213
214 /***
215 * Print a string.
216 */
217 public void print(String s)
218 {
219 log(s);
220 }
221
222 /***
223 * Print an object.
224 */
225 public void print(Object obj)
226 {
227 log(String.valueOf(obj));
228 }
229
230 /***
231 * Terminate the current line by writing the line separator string.
232 */
233 public void println()
234 {
235 // do nothing
236 }
237
238 /***
239 * Print a boolean value and then terminate the line.
240 */
241 public void println(boolean x)
242 {
243 log(String.valueOf(x));
244 }
245
246 /***
247 * Print a character and then terminate the line.
248 */
249 public void println(char x)
250 {
251 log(String.valueOf(x));
252 }
253
254 /***
255 * Print an integer and then terminate the line.
256 */
257 public void println(int x)
258 {
259 log(String.valueOf(x));
260 }
261
262 /***
263 * Print a long integer and then terminate the line.
264 */
265 public void println(long x)
266 {
267 log(String.valueOf(x));
268 }
269
270 /***
271 * Print a floating-point number and then terminate the line.
272 */
273 public void println(float x)
274 {
275 log(String.valueOf(x));
276 }
277
278 /***
279 * Print a double-precision floating-point number and then terminate the
280 * line.
281 */
282 public void println(double x)
283 {
284 log(String.valueOf(x));
285 }
286
287 /***
288 * Print an array of characters and then terminate the line.
289 */
290 public void println(char x[])
291 {
292 log(String.valueOf(x));
293 }
294
295 /***
296 * Print a String and then terminate the line.
297 */
298 public void println(String x)
299 {
300 log(x);
301 }
302
303 /***
304 * Print an Object and then terminate the line.
305 */
306 public void println(Object x)
307 {
308 log(String.valueOf(x));
309 }
310
311 /***
312 * This method returns default logger for Turbine System
313 *
314 * @return The default logger for system.
315 */
316 public Logger getLogger()
317 {
318 return logger.getLogger();
319 }
320
321 /***
322 * This method returns logger with given name if such logger exsists,
323 * or the default logger.
324 */
325 public Logger getLogger(String logName)
326 {
327 return logger.getLogger(logName);
328 }
329
330 /***
331 * This method sets the log level in default logger
332 */
333 public void setLogLevel(int level)
334 {
335 logger.setLogLevel(level);
336 }
337
338 /***
339 * This method sets the log level in the logger of given name
340 */
341 public void setLogLevel(String logName, int level)
342 {
343 logger.setLogLevel(logName, level);
344 }
345
346 /***
347 * This method sets format style of the default logger.
348 * Format tokens are described in RunDataFilter implementation.
349 *
350 * @see org.apache.turbine.services.logging.BaseRunDataFilter
351 *
352 * @param format String describing what information should be extracted from
353 * RunData
354 */
355 public void setFormat(String format)
356 {
357 logger.setFormat(format);
358 }
359
360 /***
361 * This method sets format style of the given logger.
362 * Format tokens are described in RunDataFilter implementation.
363 *
364 * @see org.apache.turbine.services.logging.BaseRunDataFilter
365 *
366 * @param format String describing what information should be extracted from
367 * RunData
368 */
369 public void setFormat(String logName, String format)
370 {
371 logger.setFormat(logName, format);
372 }
373 }
This page was automatically generated by Maven