@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; }
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(" ", " "); }
@Override @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public String format(LogRecord record) { StringBuilder builder = new StringBuilder(); builder.append(date.format(record.getMillis())); builder.append(" ["); builder.append(record.getLevel().getLocalizedName().toUpperCase()); builder.append("] "); builder.append(colorize(formatMessage(record))); builder.append('\n'); if (record.getThrown() != null) { StringWriter writer = new StringWriter(); record.getThrown().printStackTrace(new PrintWriter(writer)); builder.append(writer.toString()); } return builder.toString(); }