Esempio n. 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();
  }
Esempio n. 2
0
  public void test(TestHarness th) {
    LogRecord rec = new LogRecord(Level.CONFIG, "foo");

    // Check #1.
    rec.setMillis(12345);
    th.check(rec.getMillis(), 12345);

    // Check #2.
    rec.setMillis(-54321);
    th.check(rec.getMillis(), -54321);
  }
Esempio n. 3
0
  @Override
  public String format(LogRecord arg0) {
    StringBuffer sb = new StringBuffer();

    sb.append(getTimestamp(arg0.getMillis()));
    sb.append(SEPARATOR);
    sb.append(arg0.getMillis());
    sb.append(SEPARATOR);
    sb.append(arg0.getLevel());
    sb.append(SEPARATOR);
    sb.append(arg0.getMessage());
    sb.append("\n");

    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);
    }
  }
Esempio n. 5
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);
 }
Esempio n. 6
0
  // this method is called for every log records
  public String format(LogRecord rec) {
    StringBuffer buf = new StringBuffer(1000);
    buf.append("<tr>\n");

    // colorize any levels >= WARNING in red
    if (rec.getLevel().intValue() >= Level.WARNING.intValue()) {
      buf.append("\t<td style=\"color:red\">");
      buf.append("<b>");
      buf.append(rec.getLevel());
      buf.append("</b>");
    } else {
      buf.append("\t<td>");
      buf.append(rec.getLevel());
    }

    buf.append("</td>\n");
    buf.append("\t<td>");
    buf.append(calcDate(rec.getMillis()));
    buf.append("</td>\n");
    buf.append("\t<td>");
    buf.append(formatMessage(rec));
    buf.append("</td>\n");
    buf.append("</tr>\n");

    return buf.toString();
  }
Esempio n. 7
0
  public synchronized String format(LogRecord record) {
    StringBuffer sb = new StringBuffer();
    date.setTime(record.getMillis() + timeDiff);
    sb.append(dFormat.format(date));
    if (isShowingThreads) {
      Thread currentThread = Thread.currentThread();
      if (currentThread != lastThread) {
        lastThread = currentThread;
        lastThreadName = currentThread.getName();
      }
      sb.append(" [").append(lastThreadName).append(']');
    }
    sb.append(' ')
        .append(record.getLevel())
        .append(' ')
        .append(getAliasFor(record.getLoggerName()))
        .append('|')
        .append(record.getMessage())
        .append(EOL);

    if (record.getThrown() != null) {
      try {
        StringWriter out = new StringWriter();
        PrintWriter pout = new PrintWriter(out);
        record.getThrown().printStackTrace(pout);
        pout.close();
        sb.append(out.toString());
      } catch (Exception e) {
        // Ignore any errors while extracting stack trace
      }
    }

    return sb.toString();
  }
    @Override
    public String format(LogRecord record) {

      StringBuilder stringBuilder = new StringBuilder("[");
      stringBuilder.append(simpleDateFormat.format(new Date(record.getMillis()))).append("]");
      stringBuilder.append(" [TID:").append(getThreadId()).append("] [");
      stringBuilder.append(getCallingInfo(7));
      stringBuilder
          .append("[")
          .append(record.getLevel().getLocalizedName())
          .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();
          stringBuilder.append(sw.toString());
        } catch (Exception ex) {
          // ignore
        }
      }

      return stringBuilder.toString();
    }
 @Override
 protected void appendPrefix(LogRecord record, StringBuilder prefix) {
   Date now = new Date(record.getMillis());
   prefix.append(getShortFormatter().format(now));
   prefix.append(" ");
   super.appendPrefix(record, prefix);
 }
Esempio n. 10
0
  @Override
  public String format(LogRecord record) {
    StringBuilder sb = new StringBuilder();

    sb.append(new SimpleDateFormat("HH:mm:ss").format(new Date(record.getMillis())))
        .append(" ")
        .append(record.getLevel().getLocalizedName())
        .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 sb.toString();
  }
Esempio n. 11
0
 public String format(LogRecord record) {
   StringBuilder s = new StringBuilder(1000);
   s.append("[").append(record.getLevel()).append("] ");
   s.append(df.format(new Date(record.getMillis()))).append(" : ");
   s.append(formatMessage(record));
   s.append(LINE_SEPARATOR);
   return s.toString();
 }
 /**
  * Updates the summary statistics but does not store the given LogRecord.
  *
  * @param record the LogRecord used to collect statistics.
  */
 private synchronized void accept(final LogRecord record) {
   final long millis = record.getMillis();
   minMillis = Math.min(minMillis, millis);
   maxMillis = Math.max(maxMillis, millis);
   ++count;
   if (record.getThrown() != null) {
     ++thrown;
   }
 }
 @Override
 public String format(LogRecord record) {
   return "["
       + this.dateFormat.format(new Date(record.getMillis()))
       + "]["
       + record.getLevel().toString()
       + "] "
       + record.getMessage()
       + "\n";
 }
Esempio n. 14
0
 @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());
 }
Esempio n. 15
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();
  }
Esempio n. 16
0
 public String format(LogRecord rec) {
   StringBuffer buf = new StringBuffer(1000);
   buf.append(rec.getLevel());
   buf.append(" ");
   buf.append(calcDate(rec.getMillis()));
   buf.append(' ');
   buf.append(rec.getMessage());
   buf.append('\n');
   return buf.toString();
 }
Esempio n. 17
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();
 }
 @Override
 public String format(LogRecord rec) {
   StringBuilder buf = new StringBuilder(1000);
   buf.append(rightPad(rec.getLevel().getName(), 7));
   buf.append(rightPad(calcDate(rec.getMillis()), 19));
   buf.append(rec.getThreadID());
   buf.append(":");
   buf.append(formatMessage(rec));
   buf.append("\n");
   return buf.toString();
 }
Esempio n. 20
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();
  }
Esempio n. 21
0
  @Override
  public synchronized String format(LogRecord record) {
    String result = "";
    Object[] parameters = record.getParameters();

    // hierarchical formatting
    if (parameters != null && parameters.length > 0) {
      @SuppressWarnings("unchecked")
      Collection<String> msg = (Collection<String>) parameters[0];
      int offset = (Integer) parameters[1];

      // init
      String hour = TimeFormatting.formatTime(record.getMillis()) + " ";
      int length = hour.length();
      String space = "";
      for (int i = 0; i < length; i++) space = space + " ";
      String lvl = "";
      for (int i = 0; i < offset; i++) lvl = lvl + ".";
      if (threadNbr != null) {
        hour = hour + "(" + threadNbr + ") ";
        space = space + "    ";
      }

      // display
      int i = 0;
      for (String m : msg) {
        String pre;
        if (i == 0) pre = hour;
        else pre = space;
        result = result + pre + lvl + m;

        if (maxCols > 0) {
          String temp = null;
          while (result.length() > maxCols) {
            if (temp == null) temp = result.substring(0, maxCols);
            else temp = temp + "\n" + result.substring(0, maxCols);
            result = result.substring(maxCols);
          }
          if (temp == null) temp = result;
          else temp = temp + "\n" + result;
          result = temp;
        }

        result = result + "\n";
        i++;
      }
    }

    // classic formatting
    else result = super.format(record);

    return result;
  }
Esempio n. 22
0
 @Override
 public String format(LogRecord record) {
   StringBuilder buffer = new StringBuilder();
   buffer
       .append(getDate(record.getMillis()))
       .append(" ")
       .append("[")
       .append(record.getLevel())
       .append("] ")
       .append(formatMessage(record))
       .append("\r\n");
   return buffer.toString();
 }
  @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();
  }
 @Override
 public String format(LogRecord record) {
   Date now = new Date(record.getMillis());
   String dateString = getFullDateTriggerFormatter().format(now);
   if ((_previousDateString == null) || !_previousDateString.equals(dateString)) {
     _previousDateString = dateString;
     StringBuilder stringBuilder = new StringBuilder(getFullFormatter().format(now));
     stringBuilder.append("\n");
     stringBuilder.append(super.format(record));
     return stringBuilder.toString();
   } else {
     return super.format(record);
   }
 }
Esempio n. 25
0
        @Override
        public String format(final LogRecord record) {
          final String[] className = record.getLoggerName().split("\\.");
          final String name = className[className.length - 1];
          final int maxLen = 22;
          final String append = "...";

          return String.format(
              "[%s] %-" + maxLen + "s %s %s",
              dateFormat.format(record.getMillis()),
              name.length() > maxLen ? name.substring(0, maxLen - append.length()) + append : name,
              record.getMessage(),
              StringUtil.throwableToString(record.getThrown()));
        }
Esempio n. 26
0
 @Override
 public String format(LogRecord record) {
   Date date = new Date(record.getMillis());
   String message = record.getMessage();
   String output =
       date.toString() + " --> " + message + System.getProperty("line.separator");
   if (record.getThrown() != null) {
     output +=
         "\tCause: "
             + record.getThrown().getMessage()
             + System.getProperty("line.separator");
   }
   return output;
 }
 @Override
 public String format(LogRecord record) {
   StringBuilder b = new StringBuilder();
   //			b.append(record.getLoggerName());
   //			b.append(": ");
   b.append(DateFormat.getDateTimeInstance().format(new Date(record.getMillis())));
   b.append(" ");
   b.append(record.getLevel().getLocalizedName());
   b.append(": ");
   // b.append(record.getMessage());
   b.append(formatMessage(record));
   b.append("\n");
   return b.toString();
 }
Esempio n. 28
0
 public String format(LogRecord record) {
   Calendar c = Calendar.getInstance();
   c.setTimeInMillis(record.getMillis());
   String message =
       "["
           + c.getTime().toString()
           + "]"
           + " "
           + record.getLevel()
           + ":"
           + " "
           + record.getMessage()
           + "\n";
   return message;
 }
Esempio n. 29
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();
  }
Esempio n. 30
0
 @Override
 public String format(final LogRecord record) {
   final StringBuilder txt = new StringBuilder();
   if (showLevel) {
     txt.append(record.getLevel().getLocalizedName()).append(separator);
   }
   if (showTimestamp) {
     synchronized (dateFormat) {
       date.setTime(record.getMillis());
       txt.append(dateFormat.format(date)).append(separator);
     }
   }
   txt.append(formatMessage(record)).append('\n');
   return txt.toString();
 }