Exemple #1
0
 public void disableFileMode() {
   if (isFileModeActive()) {
     try {
       logFileWriter.close();
       if (ntClient.isRestartingModeEnabled() && ntClient.isLastRun())
         logFileWriter.rename(
             "Debug_"
                 + StringUtils.formatDateTime(System.currentTimeMillis(), "-", "", "T")
                 + ".log",
             FileIO.FILE_EXISTS_STRATEGY_CREATE_RENAMED_FILE); // rename file to seal it
       logFileWriter.dispose();
     } catch (Exception ignore) {
     } finally {
       logFileWriter = null;
       logFilePath = null;
     }
   }
 }
Exemple #2
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");
     }
   }
 }
Exemple #3
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;
   }
 }
Exemple #4
0
  public void save(String msg) {

    if (NTClient.ENVIRONMENT != NTClient.PHONE_PROD_ENV) System.out.println(msg);
    LogEntry entry = new LogEntry(msg);
    if (lineBuffer != null) lineBuffer.offer(entry);
    if (isFileModeActive()) {
      synchronized (logFileWriter) {
        try {
          logFileWriter.write(entry.toString() + "\n");
        } catch (Exception e) {
          disableFileMode();
        }
      }
    }
    if (ntWebAPI != null) {
      try {
        ntWebAPI.postLog(entry.toString() + "\n");
      } catch (Exception e) {
        ntWebAPI = null; // disable web mode
      }
    }
  }