001    /*
002    // $Id: //open/mondrian/src/main/mondrian/recorder/PrintStreamRecorder.java#5 $
003    // This software is subject to the terms of the Common Public License
004    // Agreement, available at the following URL:
005    // http://www.opensource.org/licenses/cpl.html.
006    // Copyright (C) 2005-2007 Julian Hyde and others.
007    // All Rights Reserved.
008    // You must accept the terms of that agreement to use this software.
009    */
010    package mondrian.recorder;
011    
012    import mondrian.olap.Util;
013    
014    import java.io.PrintStream;
015    
016    /**
017     * Implementation of {@link MessageRecorder} simply writes messages to
018     * PrintStreams.
019     *
020     * @version $Id: //open/mondrian/src/main/mondrian/recorder/PrintStreamRecorder.java#5 $
021     */
022    public class PrintStreamRecorder extends AbstractRecorder {
023        private final PrintStream err;
024        private final PrintStream out;
025    
026        public PrintStreamRecorder() {
027            this(System.out, System.err);
028        }
029    
030        public PrintStreamRecorder(final PrintStream out, final PrintStream err) {
031            this.out = out;
032            this.err = err;
033        }
034    
035        protected void recordMessage(
036                final String msg,
037                final Object info,
038                final MsgType msgType) {
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