Example #1
0
  public void test(TestHarness th) {
    LogRecord rec1 = new LogRecord(Level.CONFIG, "msg");
    LogRecord rec2 = new LogRecord(Level.CONFIG, "msg2");
    long s1, s2;

    s1 = rec1.getSequenceNumber();
    s2 = rec2.getSequenceNumber();

    /* Check #1.
     *
     * It could happen that rec1 has a sequence number of
     * Long.MAX_VALUE, or that rec1's sequence number is close to
     * Long.MAX_VALUE and some background threads have created a few
     * LogRecords between the creation of rec1 and rec2, so rec2's
     * sequence number is equal to or slightly greater than
     * Long.MIN_VALUE. In these cases, s2 would not be greater than
     * s1, although the implementation of java.util.logging.LogRecord
     * was entirely correct.
     *
     * While this event is extremely unlikely, it is not entirely
     * impossible, so we can perform the subsequent check only if
     * there was no arithmetic overflow.
     */
    if ((s1 >= 0) == (s2 >= 0)) th.check(s2 > s1);
    else th.check(true);

    // Check #2.
    rec2.setSequenceNumber(42);
    th.check(rec2.getSequenceNumber() == 42);

    // Check #3.
    rec2.setSequenceNumber(s2);
    th.check(rec2.getSequenceNumber() == s2);
  }
  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);
    }
  }
Example #3
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();
  }
Example #4
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();
 }
  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) {
    }
  }