import java.io.*; import javax.swing.*; public class ErrorLog extends PrintStream { static String errorfilename = "error.txt"; static int maxerrors = 10; static int excount = 0; static PrintStream okstream = null; static boolean showwarnings = true; public ErrorLog(PrintStream okstream) { super(new LogStream(okstream)); this.okstream = okstream; } public static void flushLog() { okstream.flush(); } public void logMessage() { okstream.println("This file is used by carto to store error information."); okstream.println("There is no cause for alarm,"); okstream.println("even if this file contains lots of cryptic error messages."); okstream.println("The information is for debugging purposes only.\n"); // okstream.print("Carto version info:\n"+Carto.runversion.getAbout()+"\n"); //+" Compiled "+Version.date); // okstream.println("Java runtime: " + System.getProperty("java.version")); // okstream.println("RunID = "+Persist.current.getRunID()+"\n"); } } public ErrorLog() throws FileNotFoundException { this(new PrintStream(new FileOutputStream(errorfilename))); } static public void exception(Throwable e) { if (excount++ < maxerrors) { if (showwarnings) log("Exception "+e); okstream.println("----------------"); e.printStackTrace(okstream); } } static public void exception(Throwable e,String msg) { log(msg); exception(e); } static public void exception(String msg) { Exception e = new Exception(msg); exception(e); } static public void log(String msg) { JOptionPane.showMessageDialog(null, msg+"\nThe file 'error.txt' may give more details", "Carto Error", JOptionPane.ERROR_MESSAGE); okstream.println("----------------"); okstream.println(msg); } static public void logOK(String msg) { JOptionPane.showMessageDialog(null, msg, "Carto Message", JOptionPane.INFORMATION_MESSAGE); okstream.println("----------------"); okstream.println(msg); } }