Exemplo n.º 1
0
 @Override
 public Component getListCellRendererComponent(
     JList<? extends LogRecord> list,
     LogRecord record,
     int index,
     boolean isSelected,
     boolean cellHasFocus) {
   JLabel label =
       (JLabel)
           defaultRenderer.getListCellRendererComponent(
               list, record, index, isSelected, cellHasFocus);
   String formattedText = getFormattedText(record);
   label.setText(formattedText);
   if (!isSelected) {
     if (record.getFormattedMessage().startsWith("---")
         && record.getFormattedMessage().endsWith("---")) {
       label.setForeground(Color.GRAY);
     } else if (record.getLogLevel() == LogLevel.ERROR) {
       label.setForeground(new Color(220, 0, 0));
     } else if (record.getLogLevel() == LogLevel.WARN) {
       label.setForeground(new Color(255, 135, 0));
     } else if (record.getLogLevel() == LogLevel.DEBUG) {
       label.setForeground(Color.LIGHT_GRAY);
     }
   }
   label.setBorder(border);
   return label;
 }
Exemplo n.º 2
0
 private String getFormattedText(LogRecord record) {
   String firstLine =
       String.format(
           "%7s  %s  %s",
           record.getLogLevel(),
           getTimestampRendering(record.getTimestamp()),
           record.getFormattedMessage());
   if (!record.getThrowableInfo().isPresent()) {
     return firstLine;
   }
   StringBuilder sb = new StringBuilder();
   sb.append("<html><body><span style=\"font-weight: bold;\">");
   sb.append(firstLine);
   sb.append("</span><br>\n");
   ThrowableInfo throwableInfo = record.getThrowableInfo().get();
   renderThrowableInfo(sb, throwableInfo, 0);
   sb.append("</body></html>");
   return sb.toString().replace(" ", "&nbsp;");
 }