001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2005-2005 Julian Hyde 008// Copyright (C) 2005-2009 Pentaho and others 009// All Rights Reserved. 010*/ 011package mondrian.recorder; 012 013import mondrian.olap.Util; 014 015import java.io.PrintStream; 016 017/** 018 * Implementation of {@link MessageRecorder} simply writes messages to 019 * PrintStreams. 020 */ 021public class PrintStreamRecorder extends AbstractRecorder { 022 private final PrintStream err; 023 private final PrintStream out; 024 025 public PrintStreamRecorder() { 026 this(System.out, System.err); 027 } 028 029 public PrintStreamRecorder(final PrintStream out, final PrintStream err) { 030 this.out = out; 031 this.err = err; 032 } 033 034 protected void recordMessage( 035 final String msg, 036 final Object info, 037 final MsgType msgType) 038 { 039 PrintStream ps; 040 String prefix; 041 switch (msgType) { 042 case INFO: 043 prefix = "INFO: "; 044 ps = out; 045 break; 046 case WARN: 047 prefix = "WARN: "; 048 ps = out; 049 break; 050 case ERROR: 051 prefix = "ERROR: "; 052 ps = err; 053 break; 054 default: 055 throw Util.unexpected(msgType); 056 } 057 String context = getContext(); 058 059 ps.print(prefix); 060 ps.print(context); 061 ps.print(": "); 062 ps.println(msg); 063 } 064} 065 066// End PrintStreamRecorder.java