/*============================================================================= | | NAME | | DebugLog.java | | DESCRIPTION | | Debug logging class used to print messages | to file or standard output. | | PUBLIC MEMBER FUNCTIONS | | startLog( String filename ) | off() | on() | print() | println() | | EXCEPTIONS | | startLog throws IOException if the file cannot be opened. | | NOTES | | | | BUGS | | | | AUTHOR | | Sean E. O'Connor | | LEGAL | | Prentice Version 1.1 - An Artist's Software Apprentice. | Copyright (C) 2003-2008 by Sean Erik O'Connor. All Rights Reserved. | | This program is free software; you can redistribute it and/or | modify it under the terms of the GNU General Public License | as published by the Free Software Foundation; version 2 | of the License. | | This program is distributed in the hope that it will be useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | GNU General Public License for more details. | | You should have received a copy of the GNU General Public License | along with this program; if not, write to the Free Software | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | | The author's address is artifex@seanerikoconnor.freeservers.com. | +============================================================================*/ package Prentice ; // Package name for this project. import java.io.* ; // PrintStream import View.* ; // Prentice View public class DebugLog { // Class variables, shared by all instances. public static boolean on = true ; protected static PrintStream outStream = System.out; /** Log to the standard output. For example, String logFile = "log.out" ; Debug.startLog( logFile ) ; or Debug.startLog( System.out ) ; */ public static void startLog( PrintStream out ) { outStream = out ; } // Open a file and start logging. // Create a new File object from the file nane, then a new output // stream from that, then a PrintStream object from that. public static void startLog( String filename ) throws IOException { startLog( new PrintStream( new FileOutputStream( new File( filename ) ) ) ) ; } // Turn off logging. public static void off() { on = false ; } // Turn on logging. public static void on() { on = true ; } // Print a string. public static void print( String s ) { if (on) outStream.print( s ) ; } // Print a string with a newline terminator. public static void println(String s) { if (on) outStream.print( s ) ; if (on) outStream.print( "\n" ) ; } // Just print a newline. public static void println() { if (on) outStream.print( "\n" ) ; } }