Java Code Examples for org.apache.logging.log4j.core.LogEvent#getSource()
The following examples show how to use
org.apache.logging.log4j.core.LogEvent#getSource() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogSearchJsonLayout.java From ambari-logsearch with Apache License 2.0 | 6 votes |
@Override public void serialize(LogEvent value, JsonGenerator gen, SerializerProvider provider) throws IOException { gen.writeStartObject(); gen.writeStringField("level", value.getLevel().name()); gen.writeStringField("thread_name", value.getThreadName()); gen.writeStringField("logger_name", value.getLoggerName()); if (value.getSource() != null) { StackTraceElement source = value.getSource(); if (source.getFileName() != null) { gen.writeStringField("file", source.getFileName()); } gen.writeNumberField("line_number", source.getLineNumber()); } gen.writeObjectField("log_message", getLogMessage(value)); gen.writeStringField("logtime", Long.toString(value.getTimeMillis())); gen.writeEndObject(); }
Example 2
Source File: MutableLogEvent.java From logging-log4j2 with Apache License 2.0 | 6 votes |
/** * Initialize the fields of this {@code MutableLogEvent} from another event. * Similar in purpose and usage as {@link org.apache.logging.log4j.core.impl.Log4jLogEvent.LogEventProxy}, * but a mutable version. * <p> * This method is used on async logger ringbuffer slots holding MutableLogEvent objects in each slot. * </p> * * @param event the event to copy data from */ public void initFrom(final LogEvent event) { this.loggerFqcn = event.getLoggerFqcn(); this.marker = event.getMarker(); this.level = event.getLevel(); this.loggerName = event.getLoggerName(); this.thrown = event.getThrown(); this.thrownProxy = event.getThrownProxy(); this.instant.initFrom(event.getInstant()); // NOTE: this ringbuffer event SHOULD NOT keep a reference to the specified // thread-local MutableLogEvent's context data, because then two threads would call // ReadOnlyStringMap.clear() on the same shared instance, resulting in data corruption. this.contextData.putAll(event.getContextData()); this.contextStack = event.getContextStack(); this.source = event.isIncludeLocation() ? event.getSource() : null; this.threadId = event.getThreadId(); this.threadName = event.getThreadName(); this.threadPriority = event.getThreadPriority(); this.endOfBatch = event.isEndOfBatch(); this.includeLocation = event.isIncludeLocation(); this.nanoTime = event.getNanoTime(); setMessage(event.getMessage()); }
Example 3
Source File: Log4jLogEvent.java From logging-log4j2 with Apache License 2.0 | 6 votes |
public LogEventProxy(final LogEvent event, final boolean includeLocation) { this.loggerFQCN = event.getLoggerFqcn(); this.marker = event.getMarker(); this.level = event.getLevel(); this.loggerName = event.getLoggerName(); final Message temp = event.getMessage(); message = temp instanceof ReusableMessage ? memento((ReusableMessage) temp) : temp; this.timeMillis = event.getInstant().getEpochMillisecond(); this.nanoOfMillisecond = event.getInstant().getNanoOfMillisecond(); this.thrown = event.getThrown(); this.thrownProxy = event.getThrownProxy(); this.contextData = memento(event.getContextData()); this.contextStack = event.getContextStack(); this.source = includeLocation ? event.getSource() : null; this.threadId = event.getThreadId(); this.threadName = event.getThreadName(); this.threadPriority = event.getThreadPriority(); this.isLocationRequired = includeLocation; this.isEndOfBatch = event.isEndOfBatch(); this.nanoTime = event.getNanoTime(); }
Example 4
Source File: Log4j2Test.java From flogger with Apache License 2.0 | 6 votes |
void assertLogSite(int index, String className, String methodName, int line, String file) { LogEvent event = events.get(index); StackTraceElement source = event.getSource(); assertThat(source.getClassName()).isEqualTo(className); assertThat(source.getMethodName()).isEqualTo(methodName); assertThat(source.getFileName()).isEqualTo(file); assertThat(source.getLineNumber()).isEqualTo(line); }
Example 5
Source File: SpectatorAppender.java From spectator with Apache License 2.0 | 5 votes |
@Override public void append(LogEvent event) { final LevelTag level = LevelTag.get(event.getLevel()); registry.counter(numMessages[level.ordinal()]).increment(); if (!ignoreExceptions() && event.getThrown() != null) { final String file = (event.getSource() == null) ? "unknown" : event.getSource().getFileName(); Id stackTraceId = numStackTraces[level.ordinal()] .withTag("exception", event.getThrown().getClass().getSimpleName()) .withTag("file", file); registry.counter(stackTraceId).increment(); } }
Example 6
Source File: MethodLocationPatternConverter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void format(final LogEvent event, final StringBuilder toAppendTo) { final StackTraceElement element = event.getSource(); if (element != null) { toAppendTo.append(element.getMethodName()); } }
Example 7
Source File: LineLocationPatternConverter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void format(final LogEvent event, final StringBuilder output) { final StackTraceElement element = event.getSource(); if (element != null) { output.append(element.getLineNumber()); } }
Example 8
Source File: FileLocationPatternConverter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void format(final LogEvent event, final StringBuilder output) { final StackTraceElement element = event.getSource(); if (element != null) { output.append(element.getFileName()); } }
Example 9
Source File: FullLocationPatternConverter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void format(final LogEvent event, final StringBuilder output) { final StackTraceElement element = event.getSource(); if (element != null) { output.append(element.toString()); } }
Example 10
Source File: ClassNamePatternConverter.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Format a logging event. * * @param event event to format. * @param toAppendTo string buffer to which class name will be appended. */ @Override public void format(final LogEvent event, final StringBuilder toAppendTo) { final StackTraceElement element = event.getSource(); if (element == null) { toAppendTo.append(NA); } else { abbreviate(element.getClassName(), toAppendTo); } }
Example 11
Source File: AsyncLoggerConfig.java From logging-log4j2 with Apache License 2.0 | 4 votes |
private void populateLazilyInitializedFields(final LogEvent event) { event.getSource(); event.getThreadName(); }
Example 12
Source File: CustomHTMLLayout.java From audit-log-plugin with MIT License | 4 votes |
/** * Formats as a String. * * @param event The Logging Event. * @return A String containing the LogEvent as HTML. */ @Override public String toSerializable(final LogEvent event) { final StringBuilder sbuf = getStringBuilder(); sbuf.append(Strings.LINE_SEPARATOR).append("<tr>").append(Strings.LINE_SEPARATOR); sbuf.append("<td>"); sbuf.append(DateTimeHelper.formatDateISO(event.getTimeMillis())); sbuf.append("</td>").append(Strings.LINE_SEPARATOR); final String escapedThread = Transform.escapeHtmlTags(event.getThreadName()); sbuf.append("<td title=\"").append(escapedThread).append(" thread\">"); sbuf.append(escapedThread); sbuf.append("</td>").append(Strings.LINE_SEPARATOR); sbuf.append("<td title=\"Level\""); if (event.getLevel().equals(Level.DEBUG)) { sbuf.append(" class=\"debug\">"); sbuf.append(Transform.escapeHtmlTags(String.valueOf(event.getLevel()))); } else if (event.getLevel().isMoreSpecificThan(Level.WARN)) { sbuf.append(" class=\"warn\">"); sbuf.append(Transform.escapeHtmlTags(String.valueOf(event.getLevel()))); } else { sbuf.append(Transform.escapeHtmlTags(String.valueOf(event.getLevel()))); } sbuf.append("</td>").append(Strings.LINE_SEPARATOR); String escapedLogger = Transform.escapeHtmlTags(event.getLoggerName()); if (Strings.isEmpty(escapedLogger)) { escapedLogger = LoggerConfig.ROOT; } sbuf.append("<td title=\"").append(escapedLogger).append(" logger\">"); sbuf.append(escapedLogger); sbuf.append("</td>").append(Strings.LINE_SEPARATOR); if (locationInfo) { final StackTraceElement element = event.getSource(); sbuf.append("<td>"); sbuf.append(Transform.escapeHtmlTags(element.getFileName())); sbuf.append(':'); sbuf.append(element.getLineNumber()); sbuf.append("</td>").append(Strings.LINE_SEPARATOR); } sbuf.append("<td title=\"Message\">"); sbuf.append(Transform.escapeHtmlTags(event.getMessage().getFormattedMessage()).replaceAll(REGEXP, "<br />")); sbuf.append("</td>").append(Strings.LINE_SEPARATOR); sbuf.append("</tr>").append(Strings.LINE_SEPARATOR); if (event.getContextStack() != null && !event.getContextStack().isEmpty()) { sbuf.append("<tr><td class=\"context\" "); sbuf.append("colspan=\"6\" "); sbuf.append("title=\"Nested Diagnostic Context\">"); sbuf.append("NDC: ").append(Transform.escapeHtmlTags(event.getContextStack().toString())); sbuf.append("</td></tr>").append(Strings.LINE_SEPARATOR); } if (event.getContextData() != null && !event.getContextData().isEmpty()) { sbuf.append("<tr><td class=\"context\" "); sbuf.append("colspan=\"6\" "); sbuf.append("title=\"Mapped Diagnostic Context\">"); sbuf.append("MDC: ").append(Transform.escapeHtmlTags(event.getContextData().toMap().toString())); sbuf.append("</td></tr>").append(Strings.LINE_SEPARATOR); } final Throwable throwable = event.getThrown(); if (throwable != null) { sbuf.append("<tr><td class=\"throw\" "); sbuf.append("colspan=\"6\">"); appendThrowableAsHtml(throwable, sbuf); sbuf.append("</td></tr>").append(Strings.LINE_SEPARATOR); } return sbuf.toString(); }
Example 13
Source File: Log4jLogEvent.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public Builder(final LogEvent other) { Objects.requireNonNull(other); if (other instanceof RingBufferLogEvent) { ((RingBufferLogEvent) other).initializeBuilder(this); return; } if (other instanceof MutableLogEvent) { ((MutableLogEvent) other).initializeBuilder(this); return; } this.loggerFqcn = other.getLoggerFqcn(); this.marker = other.getMarker(); this.level = other.getLevel(); this.loggerName = other.getLoggerName(); this.message = other.getMessage(); this.instant.initFrom(other.getInstant()); this.thrown = other.getThrown(); this.contextStack = other.getContextStack(); this.includeLocation = other.isIncludeLocation(); this.endOfBatch = other.isEndOfBatch(); this.nanoTime = other.getNanoTime(); // Avoid unnecessarily initializing thrownProxy, threadName and source if possible if (other instanceof Log4jLogEvent) { final Log4jLogEvent evt = (Log4jLogEvent) other; this.contextData = evt.contextData; this.thrownProxy = evt.thrownProxy; this.source = evt.source; this.threadId = evt.threadId; this.threadName = evt.threadName; this.threadPriority = evt.threadPriority; } else { if (other.getContextData() instanceof StringMap) { this.contextData = (StringMap) other.getContextData(); } else { if (this.contextData.isFrozen()) { this.contextData = ContextDataFactory.createContextData(); } else { this.contextData.clear(); } this.contextData.putAll(other.getContextData()); } this.thrownProxy = other.getThrownProxy(); this.source = other.getSource(); this.threadId = other.getThreadId(); this.threadName = other.getThreadName(); this.threadPriority = other.getThreadPriority(); } }
Example 14
Source File: LoghubAppender.java From aliyun-log-log4j2-appender with Apache License 2.0 | 4 votes |
@Override public void append(LogEvent event) { List<LogItem> logItems = new ArrayList<LogItem>(); LogItem item = new LogItem(); logItems.add(item); item.SetTime((int) (event.getTimeMillis() / 1000)); DateTime dateTime = new DateTime(event.getTimeMillis()); item.PushBack("time", dateTime.toString(formatter)); item.PushBack("level", event.getLevel().toString()); item.PushBack("thread", event.getThreadName()); StackTraceElement source = event.getSource(); if (source == null && (!event.isIncludeLocation())) { event.setIncludeLocation(true); source = event.getSource(); event.setIncludeLocation(false); } item.PushBack("location", source == null ? "Unknown(Unknown Source)" : source.toString()); String message = event.getMessage().getFormattedMessage(); item.PushBack("message", message); String throwable = getThrowableStr(event.getThrown()); if (throwable != null) { item.PushBack("throwable", throwable); } if (getLayout() != null) { item.PushBack("log", new String(getLayout().toByteArray(event))); } Optional.ofNullable(mdcFields).ifPresent( f->event.getContextMap().entrySet().stream() .filter(v->Arrays.stream(f.split(",")).anyMatch(i->i.equals(v.getKey()))) .forEach(map-> item.PushBack(map.getKey(),map.getValue())) ); try { producer.send(this.project, this.logStore, this.topic, this.source, logItems, new LoghubAppenderCallback(LOGGER, this.project, this.logStore, this.topic, this.source, logItems)); } catch (Exception e) { this.error( "Failed to send log, project=" + project + ", logStore=" + logStore + ", topic=" + topic + ", source=" + source + ", logItem=" + logItems, e); } }
Example 15
Source File: Log4j1XmlLayout.java From logging-log4j2 with Apache License 2.0 | 4 votes |
private void formatTo(final LogEvent event, final StringBuilder buf) { // We yield to the \r\n heresy. buf.append("<log4j:event logger=\""); buf.append(Transform.escapeHtmlTags(event.getLoggerName())); buf.append("\" timestamp=\""); buf.append(event.getTimeMillis()); buf.append("\" level=\""); buf.append(Transform.escapeHtmlTags(String.valueOf(event.getLevel()))); buf.append("\" thread=\""); buf.append(Transform.escapeHtmlTags(event.getThreadName())); buf.append("\">\r\n"); buf.append("<log4j:message><![CDATA["); // Append the rendered message. Also make sure to escape any existing CDATA sections. Transform.appendEscapingCData(buf, event.getMessage().getFormattedMessage()); buf.append("]]></log4j:message>\r\n"); final List<String> ndc = event.getContextStack().asList(); if (!ndc.isEmpty()) { buf.append("<log4j:NDC><![CDATA["); Transform.appendEscapingCData(buf, Strings.join(ndc, ' ')); buf.append("]]></log4j:NDC>\r\n"); } @SuppressWarnings("ThrowableResultOfMethodCallIgnored") final Throwable thrown = event.getThrown(); if (thrown != null) { buf.append("<log4j:throwable><![CDATA["); final StringWriter w = new StringWriter(); thrown.printStackTrace(new PrintWriter(w)); Transform.appendEscapingCData(buf, w.toString()); buf.append("]]></log4j:throwable>\r\n"); } if (locationInfo) { final StackTraceElement source = event.getSource(); if (source != null) { buf.append("<log4j:locationInfo class=\""); buf.append(Transform.escapeHtmlTags(source.getClassName())); buf.append("\" method=\""); buf.append(Transform.escapeHtmlTags(source.getMethodName())); buf.append("\" file=\""); buf.append(Transform.escapeHtmlTags(source.getFileName())); buf.append("\" line=\""); buf.append(source.getLineNumber()); buf.append("\"/>\r\n"); } } if (properties) { final ReadOnlyStringMap contextMap = event.getContextData(); if (!contextMap.isEmpty()) { buf.append("<log4j:properties>\r\n"); contextMap.forEach(new BiConsumer<String, String>() { @Override public void accept(final String key, final String val) { if (val != null) { buf.append("<log4j:data name=\""); buf.append(Transform.escapeHtmlTags(key)); buf.append("\" value=\""); buf.append(Transform.escapeHtmlTags(val)); buf.append("\"/>\r\n"); } } }); buf.append("</log4j:properties>\r\n"); } } buf.append("</log4j:event>\r\n\r\n"); }
Example 16
Source File: Log4j1XmlLayout.java From logging-log4j2 with Apache License 2.0 | 4 votes |
private void formatTo(final LogEvent event, final StringBuilder buf) { // We yield to the \r\n heresy. buf.append("<log4j:event logger=\""); buf.append(Transform.escapeHtmlTags(event.getLoggerName())); buf.append("\" timestamp=\""); buf.append(event.getTimeMillis()); buf.append("\" level=\""); buf.append(Transform.escapeHtmlTags(String.valueOf(event.getLevel()))); buf.append("\" thread=\""); buf.append(Transform.escapeHtmlTags(event.getThreadName())); buf.append("\">\r\n"); buf.append("<log4j:message><![CDATA["); // Append the rendered message. Also make sure to escape any existing CDATA sections. Transform.appendEscapingCData(buf, event.getMessage().getFormattedMessage()); buf.append("]]></log4j:message>\r\n"); final List<String> ndc = event.getContextStack().asList(); if (!ndc.isEmpty()) { buf.append("<log4j:NDC><![CDATA["); Transform.appendEscapingCData(buf, Strings.join(ndc, ' ')); buf.append("]]></log4j:NDC>\r\n"); } @SuppressWarnings("ThrowableResultOfMethodCallIgnored") final Throwable thrown = event.getThrown(); if (thrown != null) { buf.append("<log4j:throwable><![CDATA["); final StringWriter w = new StringWriter(); thrown.printStackTrace(new PrintWriter(w)); Transform.appendEscapingCData(buf, w.toString()); buf.append("]]></log4j:throwable>\r\n"); } if (locationInfo) { final StackTraceElement source = event.getSource(); if (source != null) { buf.append("<log4j:locationInfo class=\""); buf.append(Transform.escapeHtmlTags(source.getClassName())); buf.append("\" method=\""); buf.append(Transform.escapeHtmlTags(source.getMethodName())); buf.append("\" file=\""); buf.append(Transform.escapeHtmlTags(source.getFileName())); buf.append("\" line=\""); buf.append(source.getLineNumber()); buf.append("\"/>\r\n"); } } if (properties) { final ReadOnlyStringMap contextMap = event.getContextData(); if (!contextMap.isEmpty()) { buf.append("<log4j:properties>\r\n"); contextMap.forEach(new BiConsumer<String, String>() { @Override public void accept(final String key, final String val) { if (val != null) { buf.append("<log4j:data name=\""); buf.append(Transform.escapeHtmlTags(key)); buf.append("\" value=\""); buf.append(Transform.escapeHtmlTags(val)); buf.append("\"/>\r\n"); } } }); buf.append("</log4j:properties>\r\n"); } } buf.append("</log4j:event>\r\n\r\n"); }
Example 17
Source File: Log4jLogEventBenchmark.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public StackTraceElement getEventSource(final String loggerName) { final LogEvent event = Log4jLogEvent.newBuilder().setLoggerName(loggerName) .setLoggerFqcn(FQCN).setLevel(Level.INFO).setMessage(MESSAGE).build(); event.setIncludeLocation(true); return event.getSource(); }
Example 18
Source File: GelfAppender.java From log4j2-gelf with Apache License 2.0 | 4 votes |
@Override public void append(LogEvent event) { final Layout<? extends Serializable> layout = getLayout(); final String formattedMessage; if (layout == null) { formattedMessage = event.getMessage().getFormattedMessage(); } else { formattedMessage = new String(layout.toByteArray(event), StandardCharsets.UTF_8); } final GelfMessageBuilder builder = new GelfMessageBuilder(formattedMessage, hostName) .timestamp(event.getTimeMillis() / 1000d) .level(GelfMessageLevel.fromNumericLevel(Severity.getSeverity(event.getLevel()).getCode())) .additionalField("loggerName", event.getLoggerName()) .additionalField("threadName", event.getThreadName()); final Marker marker = event.getMarker(); if (marker != null) { builder.additionalField("marker", marker.getName()); } if (includeThreadContext) { for (Map.Entry<String, String> entry : event.getContextMap().entrySet()) { builder.additionalField(entry.getKey(), entry.getValue()); } // Guard against https://issues.apache.org/jira/browse/LOG4J2-1530 final ThreadContext.ContextStack contextStack = event.getContextStack(); if (contextStack != null) { final List<String> contextStackItems = contextStack.asList(); if (contextStackItems != null && !contextStackItems.isEmpty()) { builder.additionalField("contextStack", contextStackItems.toString()); } } } if (includeSource) { final StackTraceElement source = event.getSource(); if (source != null) { builder.additionalField("sourceFileName", source.getFileName()); builder.additionalField("sourceMethodName", source.getMethodName()); builder.additionalField("sourceClassName", source.getClassName()); builder.additionalField("sourceLineNumber", source.getLineNumber()); } } @SuppressWarnings("all") final Throwable thrown = event.getThrown(); if (includeStackTrace && thrown != null) { String stackTrace; if (includeExceptionCause) { final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); thrown.printStackTrace(printWriter); stackTrace = stringWriter.toString(); } else { stackTrace = getSimpleStacktraceAsString(thrown); } builder.additionalField("exceptionClass", thrown.getClass().getCanonicalName()); builder.additionalField("exceptionMessage", thrown.getMessage()); builder.additionalField("exceptionStackTrace", stackTrace); builder.fullMessage(formattedMessage); } if (!additionalFields.isEmpty()) { builder.additionalFields(additionalFields); } final GelfMessage gelfMessage = builder.build(); try { final boolean sent = client.trySend(gelfMessage); if (!sent) { LOG.debug("Couldn't send message: {}", gelfMessage); } } catch (Exception e) { throw new AppenderLoggingException("failed to write log event to GELF server: " + e.getMessage(), e); } }
Example 19
Source File: SystemdJournalAppender.java From log4j-systemd-journal-appender with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void append(LogEvent event) { List<Object> args = new ArrayList<>(); args.add(buildFormattedMessage(event)); args.add("PRIORITY=%d"); args.add(Integer.valueOf(log4jLevelToJournalPriority(event.getLevel()))); if (logThreadName) { args.add("THREAD_NAME=%s"); args.add(event.getThreadName()); } if (logLoggerName) { args.add("LOG4J_LOGGER=%s"); args.add(event.getLoggerName()); } if (logAppenderName) { args.add("LOG4J_APPENDER=%s"); args.add(getName()); } if (logStacktrace && event.getThrown() != null) { StringWriter stacktrace = new StringWriter(); event.getThrown().printStackTrace(new PrintWriter(stacktrace)); args.add("STACKTRACE=%s"); args.add(stacktrace.toString()); } if (logSource && event.getSource() != null) { String fileName = event.getSource().getFileName(); args.add("CODE_FILE=%s"); args.add(fileName); String methodName = event.getSource().getMethodName(); args.add("CODE_FUNC=%s"); args.add(methodName); int lineNumber = event.getSource().getLineNumber(); args.add("CODE_LINE=%d"); args.add(Integer.valueOf(lineNumber)); } if (logThreadContext) { ReadOnlyStringMap context = event.getContextData(); if (context != null) { for (Entry<String, String> entry : context.toMap().entrySet()) { String key = entry.getKey(); args.add(threadContextPrefix + normalizeKey(key) + "=%s"); args.add(entry.getValue()); } } } if (syslogIdentifier != null && !syslogIdentifier.isEmpty()) { args.add("SYSLOG_IDENTIFIER=%s"); args.add(syslogIdentifier); } if (syslogFacility != null && !syslogFacility.isEmpty()) { args.add("SYSLOG_FACILITY=%d"); args.add(Integer.valueOf(syslogFacility)); } args.add(null); // null terminated journalLibrary.sd_journal_send("MESSAGE=%s", args.toArray()); }
Example 20
Source File: HtmlLayout.java From logging-log4j2 with Apache License 2.0 | 4 votes |
/** * Formats as a String. * * @param event The Logging Event. * @return A String containing the LogEvent as HTML. */ @Override public String toSerializable(final LogEvent event) { final StringBuilder sbuf = getStringBuilder(); sbuf.append(Strings.LINE_SEPARATOR).append("<tr>").append(Strings.LINE_SEPARATOR); sbuf.append("<td>"); sbuf.append(event.getTimeMillis() - jvmStartTime); sbuf.append("</td>").append(Strings.LINE_SEPARATOR); final String escapedThread = Transform.escapeHtmlTags(event.getThreadName()); sbuf.append("<td title=\"").append(escapedThread).append(" thread\">"); sbuf.append(escapedThread); sbuf.append("</td>").append(Strings.LINE_SEPARATOR); sbuf.append("<td title=\"Level\">"); if (event.getLevel().equals(Level.DEBUG)) { sbuf.append("<font color=\"#339933\">"); sbuf.append(Transform.escapeHtmlTags(String.valueOf(event.getLevel()))); sbuf.append("</font>"); } else if (event.getLevel().isMoreSpecificThan(Level.WARN)) { sbuf.append("<font color=\"#993300\"><strong>"); sbuf.append(Transform.escapeHtmlTags(String.valueOf(event.getLevel()))); sbuf.append("</strong></font>"); } else { sbuf.append(Transform.escapeHtmlTags(String.valueOf(event.getLevel()))); } sbuf.append("</td>").append(Strings.LINE_SEPARATOR); String escapedLogger = Transform.escapeHtmlTags(event.getLoggerName()); if (Strings.isEmpty(escapedLogger)) { escapedLogger = LoggerConfig.ROOT; } sbuf.append("<td title=\"").append(escapedLogger).append(" logger\">"); sbuf.append(escapedLogger); sbuf.append("</td>").append(Strings.LINE_SEPARATOR); if (locationInfo) { final StackTraceElement element = event.getSource(); sbuf.append("<td>"); sbuf.append(Transform.escapeHtmlTags(element.getFileName())); sbuf.append(':'); sbuf.append(element.getLineNumber()); sbuf.append("</td>").append(Strings.LINE_SEPARATOR); } sbuf.append("<td title=\"Message\">"); sbuf.append(Transform.escapeHtmlTags(event.getMessage().getFormattedMessage()).replaceAll(REGEXP, "<br />")); sbuf.append("</td>").append(Strings.LINE_SEPARATOR); sbuf.append("</tr>").append(Strings.LINE_SEPARATOR); if (event.getContextStack() != null && !event.getContextStack().isEmpty()) { sbuf.append("<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : ").append(fontSize); sbuf.append(";\" colspan=\"6\" "); sbuf.append("title=\"Nested Diagnostic Context\">"); sbuf.append("NDC: ").append(Transform.escapeHtmlTags(event.getContextStack().toString())); sbuf.append("</td></tr>").append(Strings.LINE_SEPARATOR); } if (event.getContextData() != null && !event.getContextData().isEmpty()) { sbuf.append("<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : ").append(fontSize); sbuf.append(";\" colspan=\"6\" "); sbuf.append("title=\"Mapped Diagnostic Context\">"); sbuf.append("MDC: ").append(Transform.escapeHtmlTags(event.getContextData().toMap().toString())); sbuf.append("</td></tr>").append(Strings.LINE_SEPARATOR); } final Throwable throwable = event.getThrown(); if (throwable != null) { sbuf.append("<tr><td bgcolor=\"#993300\" style=\"color:White; font-size : ").append(fontSize); sbuf.append(";\" colspan=\"6\">"); appendThrowableAsHtml(throwable, sbuf); sbuf.append("</td></tr>").append(Strings.LINE_SEPARATOR); } return sbuf.toString(); }