Exemplo n.º 1
0
  protected int encodeLogViewLink(
      MessageTree tree, Message message, ChannelBuffer buf, int level, LineCounter counter) {
    BufferHelper helper = m_bufferHelper;
    int count = 0;

    if (counter != null) {
      counter.inc();

      count += helper.tr1(buf, "link");
    } else {
      count += helper.tr1(buf, null);
    }

    String link = buildLink(message);

    count += helper.td1(buf);

    count += helper.nbsp(buf, level * 2); // 2 spaces per level
    count +=
        helper.write(
            buf,
            String.format(
                "<a href=\"%s%s\" onclick=\"return show(this,'%s');\">[:: show ::]</a>",
                m_logViewPrefix, link, link));
    count += helper.td2(buf);

    count += helper.td(buf, "<div id=\"" + link + "\"></div>", "colspan=\"4\"");

    count += helper.tr2(buf);
    count += helper.crlf(buf);

    return count;
  }
Exemplo n.º 2
0
 @Test
 public void testCountLines() {
   String s = "foo\nbar\nbaz\n";
   assertEquals(3, LineCounter.countLines(s));
   assertEquals(0, LineCounter.countLines("foo"));
 }
 protected void execute(LineCounter counter) {
   counter.run();
   synchronized (this) {
     System.out.println(counter.getFilename() + " " + counter.getCount());
   }
 }
Exemplo n.º 4
0
  protected int encodeLine(
      MessageTree tree,
      Message message,
      ChannelBuffer buf,
      char type,
      Policy policy,
      int level,
      LineCounter counter) {
    BufferHelper helper = m_bufferHelper;
    int count = 0;

    if (counter != null) {
      counter.inc();

      count += helper.tr1(buf, counter.getCount() % 2 != 0 ? "odd" : "even");
    } else {
      count += helper.tr1(buf, null);
    }

    count += helper.td1(buf);

    count += helper.nbsp(buf, level * 2); // 2 spaces per level
    count += helper.write(buf, (byte) type);

    if (type == 'T' && message instanceof Transaction) {
      long duration = ((Transaction) message).getDurationInMillis();

      count += helper.write(buf, m_dateHelper.format(message.getTimestamp() + duration));
    } else {
      count += helper.write(buf, m_dateHelper.format(message.getTimestamp()));
    }

    count += helper.td2(buf);

    count += helper.td(buf, message.getType());
    count += helper.td(buf, message.getName());

    if (policy != Policy.WITHOUT_STATUS) {
      if (Message.SUCCESS.equals(message.getStatus())) {
        count += helper.td(buf, "&nbsp;"); // do not output "0"
      } else {
        count += helper.td(buf, message.getStatus(), "class=\"error\"");
      }

      Object data = message.getData();

      count += helper.td1(buf);

      if (policy == Policy.WITH_DURATION && message instanceof Transaction) {
        long durationInMicro = ((Transaction) message).getDurationInMicros();
        long durationInMillis = durationInMicro / 1000L;

        if (durationInMicro < 100L) {
          count += helper.write(buf, String.format("%.2f", durationInMicro / 1000.0));
        } else if (durationInMicro < 10000L) { // less than 10 ms
          count += helper.write(buf, String.format("%.2f", durationInMicro / 1000.0));
        } else { // no fraction
          count += helper.write(buf, Long.toString(durationInMillis));
        }

        count += helper.write(buf, "ms ");
      }

      count += helper.writeRaw(buf, String.valueOf(data));
      count += helper.td2(buf);
    } else {
      count += helper.td(buf, "");
      count += helper.td(buf, "");
    }

    count += helper.tr2(buf);
    count += helper.crlf(buf);

    return count;
  }