package sudoku;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;

/**
 * <p>This class provides less verbose {@link #log(String) access} 
 * to a log file to which to print debugging information.</p>
 * @author fiveham
 *
 */
public class Debug {
	
	private static final PrintStream log = /*System.out;*/initLog();
	
	/**
	 * <p>Creates the PrintStream referred to by {@code log}, 
	 * which points to a file named "dump.txt".</p>
	 * <p>{@code log} is initialized by a call to this method.</p>
	 * @return the PrintStream to be stored in {@code log}
	 */
	private static PrintStream initLog(){
		try{
			File f = new File("dump.txt");
			System.out.println("Creating log file: "+f.getAbsolutePath());
			return new PrintStream(f);
		} catch(FileNotFoundException e){
			System.out.println("Error: Could not open log file for writing.");
			System.exit(1);
			return null;
		}
	}
	
	/**
	 * <p>Prints {@code s} to the file specified by {@code log}.</p>
	 * @param s the string to be printed to the file specified by 
	 * {@code log}
	 */
	public static void log(Object s){
		log.println(s);
	}
	
	/**
	 * <p>Prints a newline to the file specified by {@code log}.</p>
	 */
	public static void log(){
		log.println();
	}
}

@@ -96,16 +96,54 @@
 tStream;
+%0Aimport java.util.function.BiConsumer;
 %0A%0A/**%0A *
@@ -319,16 +319,68 @@
 bug %7B%0A%09%0A
+%09private static final State state = State.NO_LOG;%0A%09%0A
 %09private
@@ -427,11 +427,11 @@
 .out
-;
 */
+ 
 init
@@ -1197,28 +1197,30 @@
 t s)%7B%0A%09%09
-log.println(
+state.log(log,
 s);%0A%09%7D%0A%09
@@ -1329,22 +1329,340 @@
 %7B%0A%09%09
-log.println();
+state.log(log,%22%22);%0A%09%7D%0A%09%0A%09private static enum State%7B%0A%09%09NO_LOG( (ps,o) -%3E %7B%7D),%0A%09%09LOG( (ps,o) -%3E ps.println(o));%0A%09%09%0A%09%09private final BiConsumer%3CPrintStream,Object%3E writer;%0A%09%09%0A%09%09private State(BiConsumer%3CPrintStream,Object%3E writer)%7B%0A%09%09%09this.writer = writer;%0A%09%09%7D%0A%09%09%0A%09%09private void log(PrintStream ps, Object o)%7B%0A%09%09%09writer.accept(ps,o);%0A%09%09%7D
 %0A%09%7D%0A

add logging-state enum to Debug to easily turn logging off/on