From 293b6732cd878303958a183b90c93ac822072384 Mon Sep 17 00:00:00 2001 From: mmichalek Date: Fri, 20 Apr 2018 13:04:20 -0400 Subject: [PATCH] 0003524: Indicate when the JVM has optimized a stack in the log --- .../jumpmind/util/SymRollingFileAppender.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/symmetric-util/src/main/java/org/jumpmind/util/SymRollingFileAppender.java b/symmetric-util/src/main/java/org/jumpmind/util/SymRollingFileAppender.java index e2e16ddf4b..1a78b2587d 100644 --- a/symmetric-util/src/main/java/org/jumpmind/util/SymRollingFileAppender.java +++ b/symmetric-util/src/main/java/org/jumpmind/util/SymRollingFileAppender.java @@ -23,6 +23,7 @@ import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStream; +import java.io.UnsupportedEncodingException; import java.io.Writer; import java.util.LinkedHashMap; import java.util.Map; @@ -96,14 +97,26 @@ protected String toKey(LoggingEvent event) { } try { - CRC32 crc = new CRC32(); - crc.update(ArrayUtils.toString(event.getThrowableStrRep()).getBytes("UTF8")); - return event.getThrowableInformation().getThrowable().getClass().getSimpleName() + ":" + crc.getValue(); + StringBuilder buff = new StringBuilder(128); + Throwable throwable = event.getThrowableInformation().getThrowable(); + buff.append(throwable.getClass().getSimpleName()); + if (throwable.getStackTrace().length == 0) { + buff.append("-jvm-optimized"); + } + buff.append(":"); + buff.append(getThrowableHash(event.getThrowableStrRep())); + return buff.toString(); } catch (Exception ex) { LogLog.error("Failed to hash stack trace.", ex); return null; } } + + protected long getThrowableHash(String[] throwableString) throws UnsupportedEncodingException { + CRC32 crc = new CRC32(); + crc.update(ArrayUtils.toString(throwableString).getBytes("UTF8")); + return crc.getValue(); + } protected LoggingEvent appendKey(LoggingEvent event, String key) { String message = getMessageWithKey(event, key, ".init");