/*============================================================================= | | 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-2009 by Sean Erik O'Connor. All Rights Reserved. | | Primpoly Version 10.4 - A Program for Computing Primitive Polynomials. | Copyright (C) 1999-2009 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, either version 3 of the License, or | (at your option) any later version. | | 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, see . | | The author's address is artificer!AT!seanerikoconnor!DOT!freeservers!DOT!com | with !DOT! replaced by . and the !AT! replaced by @ | +============================================================================*/ 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" ) ; } }