KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > recorder > PrintStreamRecorder


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/recorder/PrintStreamRecorder.java#3 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2005-2006 Julian Hyde and others.
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.recorder;
11
12 import java.io.PrintStream JavaDoc;
13
14 /**
15  * Implementation of {@link MessageRecorder} simply writes messages to
16  * PrintStreams.
17  */

18 public class PrintStreamRecorder extends AbstractRecorder {
19     private final PrintStream JavaDoc err;
20     private final PrintStream JavaDoc out;
21     public PrintStreamRecorder() {
22         this(System.out, System.err);
23     }
24     public PrintStreamRecorder(final PrintStream JavaDoc out, final PrintStream JavaDoc err) {
25         this.out = out;
26         this.err = err;
27     }
28     protected void recordMessage(
29             final String JavaDoc msg,
30             final Object JavaDoc info,
31             final MsgType msgType) {
32         PrintStream JavaDoc ps = null;
33         String JavaDoc prefix;
34         switch (msgType) {
35         case INFO:
36             prefix = "INFO: ";
37             ps = out;
38             break;
39         case WARN:
40             prefix = "WARN: ";
41             ps = out;
42             break;
43         case ERROR:
44             prefix = "ERROR: ";
45             ps = err;
46             break;
47         default:
48             prefix = "UNKNOWN: ";
49         }
50         String JavaDoc context = getContext();
51
52         ps.print(prefix);
53         ps.print(context);
54         ps.print(": ");
55         ps.println(msg);
56     }
57 }
58
59 // End PrintStreamRecorder.java
60
Popular Tags