コード例 #1
0
  private static void writeMessage(final String message) {

    /**
     * ignore any logging if we have set some inclusive values with
     *
     * <p>-Dorg.jpedal.inclusiveLogFilters="memory,error"
     *
     * <p>Values are case-insensitve and example above would only output messages containing
     * 'memory' or 'error')
     */
    if (filterValues != null && message != null) {
      boolean found = false;

      for (final String s : filterValues) {
        if (message.toLowerCase().contains(s)) {
          found = true;
          break;
        }
      }
      if (!found) {
        return;
      }
    }

    // implement your own version of org.jpedal.utils.LogScanner
    // and set will then allow you to track any error messages
    if (logScanner != null) {
      logScanner.message(message);
    }

    /** write message to pane if client active and put to front */
    if (verbose) {
      System.out.println(message);
    }

    if (log_name != null) {

      // write message
      final PrintWriter log_file;
      try {
        log_file = new PrintWriter(new FileWriter(log_name, true));

        if (!testing) {
          log_file.println(TimeNow.getTimeNow() + ' ' + message); // write date to the log
        }
        log_file.println(message);
        log_file.flush();
        log_file.close();
      } catch (final Exception e) {
        System.err.println("Exception " + e + " attempting to write to log file " + log_name);
      }
    }
  }
コード例 #2
0
  /** setup log file and check it is readable also sets command line options */
  public static final void setupLogFile(final String command_line_values) {

    if (command_line_values != null) {

      // verbose mode echos to screen
      if (command_line_values.indexOf('v') != -1) {
        verbose = true;
        writeLog("Verbose on");
      } else {
        verbose = false;
      }
    }

    // write out info
    if (!testing) {
      writeLog("Software started - " + TimeNow.getTimeNow());
    }
    writeLog("=======================================================");
  }