1    import java.io.*;
2    import javax.swing.*;
3    
4    public class ErrorLog extends PrintStream {
5    
6      static String errorfilename = "error.txt";
7      static int maxerrors = 10;
8      static int excount = 0;
9      static PrintStream okstream = null;
10   
11     static boolean showwarnings = false;
12   
13     public ErrorLog(PrintStream okstream) {
14       super(new LogStream(okstream));
15       this.okstream = okstream;
16     }
17   
18     public static void flushLog() {
19       okstream.flush();
20     }
21   
22     public void logMessage() {
23       okstream.println("This file is used by carto to store error information.");
24       okstream.println("There is no cause for alarm,");
25       okstream.println("even if this file contains lots of cryptic error messages.");
26       okstream.println("The information is for debugging purposes only.\n");
27       okstream.print("Carto  version info:\n"+Carto.runversion.getAbout()+"\n");
28   //+" Compiled "+Version.date);
29   //    okstream.println("Java runtime: " + System.getProperty("java.version"));
30   //    okstream.println("RunID = "+Persist.current.getRunID()+"\n");  }
31     }
32   
33     public ErrorLog() throws FileNotFoundException {
34       this(new PrintStream(new FileOutputStream(errorfilename)));
35     }
36   
37     static public void exception(Throwable e) {
38       if (excount++ < maxerrors) {
39         if (showwarnings) log("Exception "+e);
40         okstream.println("----------------");
41         e.printStackTrace(okstream);
42       }
43     }
44   
45     static public void exception(Throwable e,String msg) {
46       log(msg);
47       exception(e);
48     }
49   
50     static public void exception(String msg) {
51       Exception e = new Exception(msg);
52       exception(e);
53     }
54   
55     static public void log(String msg) {
56       JOptionPane.showMessageDialog(null,
57           			  msg+"\nThe file 'error.txt' may give more details",
58           			  "Carto Error",
59           			  JOptionPane.ERROR_MESSAGE);
60       okstream.println("----------------");
61       okstream.println(msg);
62     }
63   
64     static public void logOK(String msg) {
65       JOptionPane.showMessageDialog(null,
66           			  msg,
67           			  "Carto Message",
68           			  JOptionPane.INFORMATION_MESSAGE);
69       okstream.println("----------------");
70       okstream.println(msg);
71     }
72   }
73   
74   
75   
76   
77   
78