Пример #1
0
 public void enableFileMode() {
   if (!isFileModeActive()) {
     if (ntClient == null)
       throw new NullPointerException("NTClient cannot be null (Logger.enableFileMode())");
     try {
       String folderPath = ntClient.getPreferences().getDataFolderPath();
       if (folderPath == null) throw new Exception("No accessible data folder");
       logFilePath = folderPath + "Debug_";
       if (ntClient.isRestartingModeEnabled()) {
         logFilePath += "RUNNING.log"; // will be renamed after last run
         logFileWriter = ntClient.getFileWriter(logFilePath);
         if (ntClient.isFirstRun()
             && logFileWriter
                 .fileExists()) { // This is a log file of an older unresumed running session,
           // let's close it:
           debug("Found unresumed \"RUNNING\" log file, renaming");
           long lastChanged = logFileWriter.fileLastChanged();
           logFileWriter.open(
               FileIO.FILE_EXISTS_STRATEGY_APPEND, FileIO.FILE_DOES_NOT_EXIST_STRATEGY_CREATE);
           logFileWriter.writeLine(
               "[LATER: "
                   + StringUtils.formatDateTime(System.currentTimeMillis(), "/", ":", " ")
                   + "] Session was never resumed, closing.");
           logFileWriter.rename(
               "Debug_" + StringUtils.formatDateTime(lastChanged, "-", "", "T") + ".log",
               FileIO.FILE_EXISTS_STRATEGY_REPLACE);
           logFileWriter.dispose(); // also calls close()
           // Again take the (new) log file:
           logFileWriter = ntClient.getFileWriter(logFilePath);
         }
         logFileWriter.open(
             FileIO.FILE_EXISTS_STRATEGY_APPEND, FileIO.FILE_DOES_NOT_EXIST_STRATEGY_CREATE);
       } else {
         logFilePath +=
             StringUtils.formatDateTime(System.currentTimeMillis(), "-", "", "T") + ".log";
         logFileWriter = ntClient.getFileWriter(logFilePath);
         logFileWriter.open(
             FileIO.FILE_EXISTS_STRATEGY_CREATE_RENAMED_FILE,
             FileIO.FILE_DOES_NOT_EXIST_STRATEGY_CREATE);
       }
       // write log buffer:
       logFileWriter.write(getBuffer(true));
       // debug("Logger file mode enabled");
     } catch (Exception e) {
       disableFileMode();
       error(e, "Failed to enable file mode in Logger");
     }
   }
 }
Пример #2
0
 public void dumpCrashLog(String folderPath) throws Exception {
   if (ntClient == null)
     throw new NullPointerException("NTClient cannot be null (Logger.dumpCrashLog())");
   try {
     logFileWriter =
         ntClient.getFileWriter(
             folderPath
                 + "Crash_"
                 + StringUtils.formatDateTime(System.currentTimeMillis(), "-", "", "T")
                 + ".log");
     logFileWriter.open(
         FileIO.FILE_EXISTS_STRATEGY_REPLACE, FileIO.FILE_DOES_NOT_EXIST_STRATEGY_CREATE);
     debug("Dumping crash log...");
     logFileWriter.write(getBuffer(true));
     logFileWriter.close();
     logFileWriter.dispose();
   } catch (Exception ignore) {
   } finally {
     logFileWriter = null;
   }
 }