示例#1
1
  @Override
  public String format(LogRecord record) {

    int count = Thread.activeCount();

    Thread th[] = new Thread[count];
    // returns the number of threads put into the array
    Thread.enumerate(th);

    String thrName = null;

    // prints active threads
    for (int i = 0; i < count; i++) {

      if (th[i] != null && th[i].getId() == record.getThreadID()) {

        thrName = th[i].getName();
        break;
      }
    }

    if (thrName == null) {
      thrName = String.format("id:%d", record.getThreadID());
    }

    StringBuilder sb = new StringBuilder();

    sb.append(new Date(record.getMillis()))
        .append(" ")
        .append(record.getLevel().getLocalizedName())
        .append(" ")
        .append("[")
        .append(record.getSourceClassName())
        .append("]")
        .append("{")
        .append(thrName)
        .append("}: ")
        .append(formatMessage(record))
        .append(LINE_SEPARATOR);

    if (record.getThrown() != null) {
      try {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        record.getThrown().printStackTrace(pw);
        pw.close();
        sb.append(sw.toString());
      } catch (Exception ex) {
        // ignore
      }
    }

    return "RT: " + sb.toString();
  }
示例#2
0
 @Override
 @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
 public synchronized String format(final LogRecord record) {
   dat.setTime(record.getMillis());
   String source;
   if (record.getSourceClassName() != null) {
     source = record.getSourceClassName();
     if (record.getSourceMethodName() != null) {
       source += "#" + record.getSourceMethodName();
     }
   } else {
     source = record.getLoggerName();
   }
   String message = formatMessage(record);
   String throwable = "";
   if (record.getThrown() != null) {
     StringWriter sw = new StringWriter();
     PrintWriter pw = new PrintWriter(sw);
     pw.println();
     record.getThrown().printStackTrace(pw);
     pw.close();
     throwable = sw.toString();
   }
   return String.format(
       FORMAT,
       dat,
       source,
       record.getLoggerName(),
       record.getLevel().getLocalizedName(),
       message,
       throwable);
 }
示例#3
0
  /**
   * @param record
   * @param sb
   */
  private void printSourceClassName(LogRecord record, StringBuffer sb) {
    if (record.getSourceClassName() != null) {
      sb.append(record.getSourceClassName());
    } else {
      sb.append(record.getLoggerName());
    }

    sb.append(seperator);
  }
  @Override
  public String format(LogRecord record) {

    String stackTrace = "";
    Throwable throwable = record.getThrown();
    if (throwable != null) {
      StringWriter sw = new StringWriter();
      throwable.printStackTrace(new PrintWriter(sw));
      stackTrace = sw.toString();
    }

    int lineNo;
    StackTraceElement[] stack = Thread.currentThread().getStackTrace();
    if (throwable != null && stack.length > 7) lineNo = stack[7].getLineNumber();
    else if (stack.length > 8) lineNo = stack[8].getLineNumber();
    else lineNo = -1;

    StringBuffer b = new StringBuffer();
    if (logPolicy.isEnabled(LogPolicy.LOG_POLICY_SHOW_THREAD_ID)) {
      b.append(String.format("%2d", record.getThreadID())).append(" ");
    }
    if (logPolicy.isEnabled(LogPolicy.LOG_POLICY_SHOW_LEVEL)) {
      b.append(record.getLevel().toString()).append(" ");
    }
    if (logPolicy.isEnabled(LogPolicy.LOG_POLICY_SHOW_CLASS)) {
      b.append("[").append(getSimpleClassName(record.getSourceClassName())).append("]: ");
    }
    if (logPolicy.isEnabled(LogPolicy.LOG_POLICY_SHOW_MESSAGE)) {
      b.append(formatMessage(record));
    }
    if (logPolicy.isEnabled(LogPolicy.LOG_POLICY_SHOW_SOURCE)) {
      b.append(" - (")
          .append(record.getSourceClassName())
          .append(".java:")
          .append(lineNo)
          .append(") ");
    }
    if (logPolicy.isEnabled(LogPolicy.LOG_POLICY_SHOW_METHOD)) {
      b.append(record.getSourceMethodName()).append("()");
    }
    if (logPolicy.isEnabled(LogPolicy.LOG_POLICY_SHOW_THREAD)) {
      b.append(" in thread ").append(Thread.currentThread().getName());
    }
    if (logPolicy.dateFormat != null) {
      b.append(" at (")
          .append(logPolicy.dateFormat.format(new Date(record.getMillis())))
          .append(")");
    }
    b.append("\n").append(stackTrace);
    return b.toString();
  }
  /*
   * (non-Javadoc)
   *
   * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
   */
  @Override
  public String format(final LogRecord logRecord) {
    //		Date recordDate = new Date(logRecord.getMillis());
    StringBuffer sb = new StringBuffer();
    try {
      // TIME and LEVEL is already at the console
      //			sb.append(LogUtils.dateToString(recordDate, UTC_Format));
      //			sb.append(" [");
      //			sb.append(logRecord.getLevel().getName());
      //			sb.append("]: ");

      //
      sb.append(logRecord.getMessage());

      sb.append("\n   (source:");
      sb.append(logRecord.getSourceClassName());
      sb.append('.');
      sb.append(logRecord.getSourceMethodName());
      if (logRecord.getThrown() != null) {
        sb.append(" - See IBM_TECHNICAL_SUPPORT\\org.openntf.log.X.Y.txt for full stack trace.");
      }
      sb.append(")");
    } catch (Throwable t) {
      System.out.println(
          "Error trying to format output for error handling. Resorting to standard stack trace...");
      t.printStackTrace();
    }
    return sb.toString();
  }
  public void log(LogRecord record) {
    if (logToFile != null) {
      logToFile(record);
    }

    if (ignoreLogging) return;

    CapedwarfRequestLogs requestLogs = getCurrentRequestLogs();
    if (requestLogs != null) {
      CapedwarfAppLogLine capedwarfAppLogLine =
          new CapedwarfAppLogLine(getCurrentRequestId(), record.getSequenceNumber());
      AppLogLine appLogLine = capedwarfAppLogLine.getAppLogLine();
      appLogLine.setLogLevel(getLogLevel(record));
      appLogLine.setLogMessage(
          record.getSourceClassName()
              + " "
              + record.getSourceMethodName()
              + ": "
              + getFormattedMessage(record)
              + "\n");
      appLogLine.setTimeUsec(record.getMillis() * 1000);
      logWriter.put(capedwarfAppLogLine);

      requestLogs.logLineAdded(appLogLine);
      logWriter.put(requestLogs);
    }
  }
示例#7
0
    /*
     * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
     */
    @Override
    public String format(final @Nullable LogRecord record) {
      assert record != null;

      final StringBuilder sb = new StringBuilder();
      sb.append(formatMessage(record));
      sb.append(" ["); // $NON-NLS-1$
      if (record.getSourceClassName() != null) {
        sb.append(record.getSourceClassName());
      }
      if (record.getSourceMethodName() != null) {
        sb.append(", "); // $NON-NLS-1$
        sb.append(record.getSourceMethodName());
      }
      sb.append("]"); // $NON-NLS-1$
      return sb.toString();
    }
示例#8
0
文件: Logging.java 项目: chhe/chatty
 @Override
 public boolean isLoggable(LogRecord record) {
   if (record.getSourceClassName().equals("chatty.util.TwitchApiRequest")) {
     if (record.getLevel() == Level.INFO) {
       return false;
     }
   }
   return true;
 }
示例#9
0
 // inefficient implementation
 public String format(final LogRecord record) {
   return record.getMillis()
       + " "
       + record.getLevel()
       + " ["
       + record.getSourceClassName()
       + "] "
       + record.getMessage()
       + "\n";
 }
 public String format(LogRecord record) {
   StringBuilder builder = new StringBuilder(1000);
   builder.append(df.format(new Date(record.getMillis()))).append(" - ");
   builder.append("[").append(record.getSourceClassName()).append(".");
   builder.append(record.getSourceMethodName()).append("] - ");
   builder.append("[").append(record.getLevel()).append("] - ");
   builder.append(formatMessage(record));
   builder.append("\n");
   return builder.toString();
 }
示例#11
0
  @Override
  public String format(LogRecord record) {

    StringBuilder sb = new StringBuilder();
    sb.append("[" + record.getLevel() + "] - ");
    sb.append(new Date(record.getMillis()) + " : ");
    sb.append(record.getSourceClassName() + "." + record.getSourceMethodName() + " : ");
    sb.append(record.getMessage() + "\n");
    return sb.toString();
  }
示例#12
0
文件: Logging.java 项目: chhe/chatty
 @Override
 public String format(LogRecord record) {
   return String.format(
       "[%1$tF %1$tT %5$s] %2$s [%3$s/%4$s]\n",
       new Date(record.getMillis()),
       record.getMessage(),
       record.getSourceClassName(),
       record.getSourceMethodName(),
       record.getLevel().getName());
 }
示例#13
0
  /**
   * Overrides SimpleFormatter format function. Writes the output without displaying the
   * date/timestamp.
   *
   * @param iRecord The log record that needs formatted.
   * @return A string formatted for a logging message
   */
  public synchronized String format(LogRecord iRecord) {
    StringBuffer sb = new StringBuffer();

    if (iRecord.getSourceClassName() != null) {
      sb.append(iRecord.getSourceClassName());
    } else {
      sb.append(iRecord.getLoggerName());
    }
    if (iRecord.getSourceMethodName() != null) {
      sb.append(" ");
      sb.append(iRecord.getSourceMethodName());
    }
    sb.append(" ");

    String message = formatMessage(iRecord);
    sb.append(iRecord.getLevel().getLocalizedName());
    sb.append(": ");
    sb.append(message);
    sb.append(mLineSeparator);

    return sb.toString();
  }
 @SuppressWarnings("unchecked")
 @Override
 public void publish(LogRecord record) {
   if (record.getLoggerName().endsWith("PluginExecutable")
       && record.getMessage().contains("PluginExecutable")) {
     try {
       Class<? extends IPluginExecutable> clazz =
           (Class<? extends IPluginExecutable>) Class.forName(record.getLoggerName());
       EventBus.getInstance().add(EventType.INFO, clazz, record.getSourceClassName());
     } catch (ClassNotFoundException e) {
       throw new RuntimeException(e);
     }
   }
 }
示例#15
0
 @Override
 public String format(LogRecord logRecord) {
   final StringBuilder result = new StringBuilder();
   result.append(logRecord.getSequenceNumber());
   result.append('[');
   result.append(logRecord.getLevel());
   result.append("] ");
   result.append(logRecord.getSourceClassName().replace("com.microsoft.reef", "c.m.r"));
   result.append('.');
   result.append(logRecord.getSourceMethodName());
   result.append(": ");
   result.append(simpleFormatter.formatMessage(logRecord));
   result.append('\n');
   return result.toString();
 }
示例#16
0
  @Override
  protected final void format0(LogRecord record, TextBuilder tb) {
    tb.append(record.getLevel()).append(" ");

    appendDateSys(record, tb);

    if (record.getLevel().intValue() > Level.INFO.intValue() || record.getThrown() != null)
      tb.append(record.getSourceClassName())
          .append(".")
          .append(record.getSourceMethodName())
          .append("(): ");

    appendMessage(record, tb);
    appendThrown(record, tb);
  }
示例#17
0
  // This method is called for every log records
  public String format(LogRecord rec) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    PrintStream printStream = new PrintStream(byteArrayOutputStream);

    printStream.format(
        "%-7s %-24s %-80s  %-40s Seq:%d Thread:%d\n",
        rec.getLevel(),
        SIMPLE_DATE_FORMAT.format(new Date(rec.getMillis())),
        rec.getMessage(),
        rec.getSourceClassName() + "." + rec.getSourceMethodName(),
        rec.getSequenceNumber(),
        rec.getThreadID());

    return byteArrayOutputStream.toString();
  }
示例#18
0
 @Override
 public void publish(final LogRecord record) {
   if (record.getLevel().intValue() < this.getLevel().intValue()
       || record.getLoggerName().equals(getClass().getName())) {
     return;
   }
   try {
     Mailer.instance()
         .send(
             (message) -> {
               message.addRecipient(
                   Message.RecipientType.TO,
                   new InternetAddress(
                       "clash.nanobot+log."
                           + record.getLevel().getName().toLowerCase()
                           + "@gmail.com"));
               message.setSubject(record.getLevel() + ": " + record.getMessage());
               String emailBody = "<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\">";
               emailBody +=
                   "<tr><td>Version</td><td>" + BuildInfo.instance().getVersion() + "</td></tr>";
               emailBody +=
                   "<tr><td>BuildTime</td><td>"
                       + BuildInfo.instance().getTimestamp()
                       + "</td></tr>";
               emailBody += "<tr><td>Time</td><td>" + record.getMillis() + "</td></tr>";
               emailBody += "<tr><td>Thread</td><td>" + record.getThreadID() + "</td></tr>";
               emailBody += "<tr><td>Logger</td><td>" + record.getLoggerName() + "</td></tr>";
               emailBody += "<tr><td>Class</td><td>" + record.getSourceClassName() + "</td></tr>";
               emailBody +=
                   "<tr><td>Method</td><td>" + record.getSourceMethodName() + "</td></tr>";
               emailBody += "<tr><td>Level</td><td>" + record.getLevel() + "</td></tr>";
               emailBody += "<tr><td>Message</td><td>" + record.getMessage() + "</td></tr>";
               final Throwable e = record.getThrown();
               if (e != null) {
                 final StringWriter writer = new StringWriter();
                 e.printStackTrace(new PrintWriter(writer));
                 emailBody +=
                     "<tr><td>Exception</td><td>"
                         + writer.toString().replace("\n", "<br/>")
                         + "</td></tr>";
               }
               emailBody += "</table>";
               message.setContent(emailBody, "text/html");
             });
   } catch (final Exception e) {
     logger.log(Level.SEVERE, e.getMessage(), e);
   }
 }
示例#19
0
  public void publish(LogRecord record, int nLogType) {
    // first see if this entry should be filtered out
    try {
      if (record != null) {

        // MARKED by zhaoxy@20101119
        /*
           if (getFilter() != null) {
        	if (!getFilter().isLoggable(record))
        		return;
        }
        */

        if (isLoggable(record)) {
          String HmuImei = null;
          String Message = record.getMessage();
          try {
            int HmuImeiPos = Message.indexOf("HMU:");
            if (HmuImeiPos >= 0) {
              HmuImei = Message.substring(HmuImeiPos + 4);
              Message = Message.substring(0, HmuImeiPos);
            }
          } catch (Exception e) {
          }

          // now store the log entry into the table
          if (activeConnection()) {
            try {
              prepInsert.setInt(1, record.getLevel().intValue());
              prepInsert.setString(2, truncate(record.getLoggerName(), 63));
              prepInsert.setString(3, truncate(Message, 255));
              prepInsert.setLong(4, record.getSequenceNumber());
              prepInsert.setString(5, truncate(record.getSourceClassName(), 63));
              prepInsert.setString(6, truncate(record.getSourceMethodName(), 31));
              prepInsert.setInt(7, record.getThreadID());
              prepInsert.setTimestamp(8, new Timestamp(System.currentTimeMillis()));
              prepInsert.setString(9, truncate(HmuImei, 15));
              prepInsert.setInt(10, nLogType);
              prepInsert.executeUpdate();
            } catch (SQLException e) {
              System.err.println("Exception on publish(record,nLogType)." + e);
            }
          }
        }
      }
    } catch (Exception e) {
    }
  }
示例#20
0
 @Override
 public String format(LogRecord rec) {
   StringWriter w1 = new StringWriter();
   PrintWriter w2 = new PrintWriter(w1);
   w2.printf(
       messageFormat,
       dateFormat.format(new Date(rec.getMillis())),
       rec.getThreadID(),
       String.valueOf(rec.getLevel()),
       fixClsName(rec.getSourceClassName()),
       fixMtdName(rec.getSourceMethodName()),
       rec.getMessage());
   w2.println();
   w2.close();
   return w1.toString();
 }
示例#21
0
 /**
  * Loggable - Don't log core java classes
  *
  * @param record log record
  * @return true
  */
 public boolean isLoggable(LogRecord record) {
   if (record.getLevel() == Level.SEVERE || record.getLevel() == Level.WARNING) return true;
   //
   String loggerName = record.getLoggerName();
   if (loggerName != null) {
     //	if (loggerName.toLowerCase().indexOf("focus") != -1)
     //		return true;
     if (loggerName.startsWith("sun.")
         || loggerName.startsWith("java.awt.")
         || loggerName.startsWith("javax.")) return false;
   }
   String className = record.getSourceClassName();
   if (className != null) {
     if (className.startsWith("sun.")
         || className.startsWith("java.awt.")
         || className.startsWith("javax.")) return false;
   }
   return true;
 } //	isLoggable
示例#22
0
 @Override
 public String format(final LogRecord record) {
   final StringBuilder logEntry = new StringBuilder();
   final Calendar cal = Calendar.getInstance();
   cal.setTimeInMillis(record.getMillis());
   logEntry.append(DateHelper.formatDate(cal));
   logEntry.append(" [");
   logEntry.append(record.getThreadID());
   logEntry.append("] ");
   logEntry.append(record.getLevel().getName());
   logEntry.append(" ");
   logEntry.append(record.getSourceClassName());
   logEntry.append(" ");
   logEntry.append(record.getSourceMethodName());
   logEntry.append(" - ");
   logEntry.append(record.getMessage());
   logEntry.append("\n");
   return logEntry.toString();
 }
示例#23
0
文件: OneLiner.java 项目: COLTRAM/nsd
 public String format(LogRecord record) {
   StringBuilder sb = new StringBuilder();
   sb.append(max5(record.getLevel().getName()));
   sb.append(" ");
   String s = record.getSourceClassName();
   int len = s.length();
   if (len > 60) {
     sb.append("...");
     sb.append(s.substring(len - 58, len));
   } else sb.append(s);
   sb.append(" ");
   sb.append(record.getSourceMethodName());
   sb.append(" ");
   while (sb.length() < 90) sb.append(".");
   sb.append(" ");
   sb.append(record.getMessage());
   sb.append("\n");
   return sb.toString();
 }
  @Override
  public String format(LogRecord record) throws RemoteException, RemoteException {
    StringBuilder sb = new StringBuilder();

    // Timestamp
    addTimestamp(sb, record.getMillis());

    // Severity
    sb.append(' ');
    sb.append(record.getLevel());

    // Thread
    sb.append(' ');
    sb.append('[');
    sb.append(Thread.currentThread().getName());
    sb.append(']');

    // Source
    sb.append(' ');
    sb.append(record.getSourceClassName());
    sb.append('.');
    sb.append(record.getSourceMethodName());

    // Message
    sb.append(' ');
    sb.append(formatMessage(record));

    // Stack trace
    if (record.getThrown() != null) {
      sb.append(ST_SEP);
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      record.getThrown().printStackTrace(pw);
      pw.close();
      sb.append(sw.getBuffer());
    }

    // New line for next record
    sb.append(LINE_SEP);

    return sb.toString();
  }
 @Override
 public String format(LogRecord logRecord) {
   Object[] arguments = new Object[6];
   arguments[0] = logRecord.getThreadID();
   String fullClassName = logRecord.getSourceClassName();
   int lastDot = fullClassName.lastIndexOf('.');
   String className = fullClassName.substring(lastDot + 1);
   arguments[1] = className;
   arguments[2] = logRecord.getSourceMethodName();
   arguments[3] = new Date(logRecord.getMillis());
   arguments[4] = logRecord.getMessage();
   if (logRecord.getThrown() != null) {
     Writer result = new StringWriter();
     logRecord.getThrown().printStackTrace(new PrintWriter(result));
     arguments[5] = result.toString();
   } else {
     arguments[5] = "";
   }
   return messageFormat.format(arguments);
 }
示例#26
0
  /* (non-Javadoc)
   * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
   */
  @Override
  public String format(LogRecord record) {
    StringBuffer sb = new StringBuffer();
    sb.append("<tr>");

    sb.append("<td>");
    sb.append(dateToString(new Date(record.getMillis()), "yyyy/MM/dd"));
    sb.append("</td>");

    sb.append("<td>");
    sb.append(dateToString(new Date(record.getMillis()), "hh:mm:ss,SSS"));
    sb.append("</td>");

    sb.append("<td>");
    if (record.getParameters() != null) {
      sb.append(record.getParameters()[0]);
    } else {
      sb.append(record.getThreadID());
    }
    sb.append("</td>");

    sb.append("<td>");
    sb.append(record.getSourceClassName());
    sb.append("</td>");

    sb.append("<td>");
    sb.append(record.getSourceMethodName());
    sb.append("</td>");

    sb.append("<td>");
    sb.append(record.getLevel());
    sb.append("</td>");

    sb.append("<td>");
    sb.append(formatMessage(record));
    sb.append("</td>");

    sb.append("</tr>");

    return sb.toString();
  }
示例#27
0
  @Override
  public String format(LogRecord r) {

    Date date = new Date(r.getMillis());
    String[] srcPkg =
        r.getSourceClassName()
            .split("\\."); // Won't work properly for sub-classes.  Who the f**k cares?

    return (date.toString()
        + "["
        + r.getLoggerName()
        + "]["
        + srcPkg[srcPkg.length - 1]
        + ":"
        + r.getSourceMethodName()
        + "]["
        + r.getLevel()
        + "]"
        + r.getMessage()
        + "\n");
  }
示例#28
0
  /**
   * Format the given LogRecord.
   *
   * @param record the log record to be formatted.
   * @return a formatted log record
   */
  @Override
  public synchronized String format(LogRecord record) {
    StringBuffer sb = m_buffer;
    sb.setLength(0);

    m_timestamp.setTime(record.getMillis());
    String tmp = record.getSourceClassName();
    m_args[1] = tmp == null ? record.getLoggerName() : tmp;
    m_args[2] = formatMessage(record);
    s_tsFormatter.format(m_args, sb, null);

    Throwable thrown = record.getThrown();
    if (thrown != null) {
      sb.append(s_lineSeparator);
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      record.getThrown().printStackTrace(pw);
      pw.close();
      sb.append(sw.toString());
    }
    return sb.toString();
  }
示例#29
0
 /* (non-Javadoc)
  * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
  */
 @Override
 public String format(LogRecord record) {
   try {
     String result = formatMessage(record);
     try {
       String sourceClassName = record.getSourceClassName();
       String sourceMethodName = record.getSourceMethodName();
       result =
           record.getLevel().getLocalizedName()
               + ": "
               + result
               + " ["
               + (sourceClassName != null ? sourceClassName : "??")
               + "#"
               + (sourceMethodName != null ? sourceMethodName : "??")
               + "]\n";
     } catch (Throwable t) {
       result = "Error formatting log message \"" + result + "\": " + t.getLocalizedMessage();
     }
     return result;
   } catch (Throwable t) {
     return "Error formatting log record: " + t.getLocalizedMessage();
   }
 }
示例#30
0
 @Override
 public boolean isLoggable(LogRecord record) {
   return record.getSourceClassName().startsWith(PREFIX);
 }