diff options
Diffstat (limited to 'NET/worlds/console/LogFile.java')
| -rw-r--r-- | NET/worlds/console/LogFile.java | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/NET/worlds/console/LogFile.java b/NET/worlds/console/LogFile.java new file mode 100644 index 0000000..54fa2d4 --- /dev/null +++ b/NET/worlds/console/LogFile.java @@ -0,0 +1,218 @@ +package NET.worlds.console; + +import NET.worlds.core.IniFile; +import NET.worlds.core.Std; +import NET.worlds.core.SystemInfo; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.text.DateFormat; +import java.util.Date; + +public class LogFile { + private static PrintStream out = null; + private static String baseName = null; + private static final String tempSuffix = ".open"; + private static final String mailSuffix = ".mail"; + private static final String noCloseTag = ", it terminated unexpectedly.\nPlease fill in the box below with an explanation of which\nfeatures you were exercising at the time, then click the\nReport button to automatically email the report to Worlds.\n"; + private static final String errorFoundTag = ", it generated a debugging log.\nPlease fill in the box below with an explanation of anything\nunusual that occurred (if anything), then click the Report\nbutton to automatically email the report to Worlds.\n"; + private static final String includeEmail = "Also, please include your email address.\n"; + private static String mailReason = "error encountered"; + private static String mailTag = ", it generated a debugging log.\nPlease fill in the box below with an explanation of anything\nunusual that occurred (if anything), then click the Report\nbutton to automatically email the report to Worlds.\n"; + private static final String iniFile = "worlds.ini"; + + public static void open() { + baseName = IniFile.gamma().getIniString("logfile", ""); + if (baseName.length() != 0) { + baseName = Gamma.earlyURLUnalias("home:" + baseName); + File f = new File(baseName + ".open"); + if (f.isFile()) { + if (scanFileForException(f)) { + mailReason = "logfile not closed--probable crash"; + mailTag = ", it terminated unexpectedly.\nPlease fill in the box below with an explanation of which\nfeatures you were exercising at the time, then click the\nReport button to automatically email the report to Worlds.\n"; + File mf = new File(baseName + ".mail"); + f.renameTo(mf); + mf = null; + } else { + f.delete(); + } + } + + f = new File(baseName); + if (f.isFile()) { + f.delete(); + } + + File var9 = null; + FileOutputStream FOout = null; + + try { + FOout = new FileOutputStream(baseName + ".open"); + } catch (IOException var6) { + System.out.println("Error opening logfile \"" + baseName + "\""); + return; + } + + out = new PrintStream(new BufferedOutputStream(FOout), true); + System.setOut(out); + System.setErr(out); + out.println("Logfile of " + DateFormat.getDateTimeInstance().format(new Date())); + out.println( + "Gamma " + + Std.getVersion() + + ":" + + "1890a40" + + ", build " + + Std.getBuildInfo() + + " of " + + DateFormat.getDateTimeInstance().format(new Date(Std.getBuildDate())) + ); + out.println("system info---------------------------------"); + SystemInfo.Record(out); + out.println("worlds.ini----------------------------------"); + + try { + String from = System.getProperty("file.encoding"); + InputStream in = new FileInputStream("worlds.ini"); + BufferedReader ini = new BufferedReader(new InputStreamReader(in, from)); + + for (String s = ini.readLine(); s != null; s = ini.readLine()) { + out.println(s); + } + + ini.close(); + } catch (IOException var7) { + } + + out.println("--------------------------------------------"); + } + } + + public static void close() { + if (out != null) { + out.println("Logfile closed."); + out.close(); + } + + File f = new File(baseName + ".open"); + if (scanFileForException(f)) { + File mf = new File(baseName + ".mail"); + f.renameTo(mf); + mf = null; + } else { + File nf = new File(baseName); + if (f.isFile()) { + f.renameTo(nf); + } + + nf = null; + } + + File var2 = null; + } + + public static void mailLogIfPresent(final String server) { + DialogReceiver rcvr = new DialogReceiver() { + @Override + public void dialogDone(Object who, boolean confirmed) { + LogMailDialog dlg = (LogMailDialog)who; + File f = new File(LogFile.baseName + ".mail"); + if (f.isFile()) { + if (confirmed) { + LogFile.sendCrashMail(server, f, LogFile.mailReason, dlg.getComment()); + } else { + f.delete(); + } + } + } + }; + File f = new File(baseName + ".mail"); + if (f.isFile()) { + String tag = "The last time you ran " + Std.getProductName() + mailTag; + if (IniFile.gamma().getIniString("LASTCHATNAME", "").length() == 0) { + new LogMailDialog(rcvr, tag + "Also, please include your email address.\n"); + } else { + new LogMailDialog(rcvr, tag); + } + } + } + + private static void sendCrashMail(String server, File logFile, String tagLine, String comment) { + MailMessage msg = new LogFileMailMessage(server, logFile); + + try { + if (tagLine != null) { + msg.appendBody(" (" + tagLine + ")"); + } + + msg.appendBody(".\n\n"); + if (comment != null) { + msg.appendBody("The user reports:\n"); + msg.appendParagraphs(comment); + msg.appendBody("\n\n"); + } + + msg.appendBody("The log file reads:\n\n"); + String from = System.getProperty("file.encoding"); + InputStream in = new FileInputStream(logFile); + BufferedReader log = new BufferedReader(new InputStreamReader(in, from)); + long fl = logFile.length(); + if (fl <= 64000L) { + for (String s = log.readLine(); s != null; s = log.readLine()) { + msg.appendBody(s + "\n"); + } + } else { + int lc = 0; + long cc = 0L; + + for (String s = log.readLine(); s != null && lc < 2048; s = log.readLine()) { + msg.appendBody(s + "\n"); + lc++; + cc += s.length(); + } + + msg.appendBody("-------------------------------------...\n"); + msg.appendBody(" Log file too long; skipping center\n"); + msg.appendBody("...-------------------------------------\n"); + log.skip(fl - (cc + 16030L)); + log.readLine(); + + for (String s = log.readLine(); s != null; s = log.readLine()) { + msg.appendBody(s + "\n"); + } + } + + log.close(); + } catch (IOException var14) { + System.out.println("Error writing logfile to mail note: " + var14); + } + + msg.send(); + } + + private static boolean scanFileForException(File logFile) { + try { + String from = System.getProperty("file.encoding"); + InputStream in = new FileInputStream(logFile); + BufferedReader log = new BufferedReader(new InputStreamReader(in, from)); + + for (String s = log.readLine(); s != null; s = log.readLine()) { + if (s.indexOf("\tat NET.worlds") != -1 || s.indexOf("\tat java.lang") != -1 || s.indexOf("\tat sun.awt") != -1) { + log.close(); + return true; + } + } + + log.close(); + } catch (IOException var5) { + } + + return false; + } +} |