import java.io.*; class LoggingFacility{ private static PrintStream ps; public static void log(String s){ try{ if (ps == null) ps = new PrintStream(new FileOutputStream("log.txt")); ps.println(s); }catch(IOException e){ System.err.println("Could not open log file"); } } public static void setLogToFile(){ try{ ps = new PrintStream( new FileOutputStream("log.txt", true) ); }catch(IOException e){ System.err.println("Could not open log file"); } } public static void setLogToConsole(){ ps = System.out; } }