@@ -103,6 +103,8 @@ public class JsonEncoder extends EncoderBase<ILoggingEvent> {
103103
104104 private static final char VALUE_SEPARATOR = COMMA_CHAR ;
105105
106+ private static final String NEWLINE = "\\ \\ n" ;
107+
106108 private boolean withSequenceNumber = true ;
107109
108110 private boolean withTimestamp = true ;
@@ -119,6 +121,7 @@ public class JsonEncoder extends EncoderBase<ILoggingEvent> {
119121 private boolean withMessage = true ;
120122 private boolean withArguments = true ;
121123 private boolean withThrowable = true ;
124+ private boolean withRawThrowable = false ;
122125 private boolean withFormattedMessage = false ;
123126
124127
@@ -190,6 +193,11 @@ public byte[] encode(ILoggingEvent event) {
190193 if (withArguments )
191194 appendArgumentArray (sb , event );
192195
196+ if (withRawThrowable ) {
197+ appenderMember (sb , "rawThrowable" , event .getThrowableProxy () != null ? getRawThrowable (event .getThrowableProxy ()) : NULL_STR );
198+ sb .append (VALUE_SEPARATOR );
199+ }
200+
193201 if (withThrowable )
194202 appendThrowableProxy (sb , THROWABLE_ATTR_NAME , event .getThrowableProxy ());
195203
@@ -298,6 +306,26 @@ private void appendThrowableProxy(StringBuilder sb, String attributeName, IThrow
298306
299307 }
300308
309+ private static String getRawThrowable (IThrowableProxy throwableProxy ) {
310+ StringBuilder sb = new StringBuilder ();
311+ getRawThrowable (throwableProxy , sb , 0 );
312+ return sb .toString ();
313+ }
314+
315+ private static void getRawThrowable (IThrowableProxy throwable , StringBuilder sb , int depth ) {
316+ if (throwable == null ) {
317+ return ;
318+ }
319+ if (depth > 0 ) {
320+ sb .append ("Caused by: " );
321+ }
322+ sb .append (throwable .getClassName ()).append (": " ).append (throwable .getMessage ()).append (NEWLINE );
323+ for (StackTraceElementProxy step : throwable .getStackTraceElementProxyArray ()) {
324+ sb .append (" " ).append (step ).append (NEWLINE );
325+ }
326+ getRawThrowable (throwable .getCause (), sb , depth + 1 );
327+ }
328+
301329 private void appendSTEPArray (StringBuilder sb , StackTraceElementProxy [] stepArray , int commonFrames ) {
302330 sb .append (QUOTE ).append (STEP_ARRAY_NAME_ATTRIBUTE ).append (QUOTE_COL ).append (OPEN_ARRAY );
303331
@@ -512,8 +540,15 @@ public void setWithThrowable(boolean withThrowable) {
512540 this .withThrowable = withThrowable ;
513541 }
514542
543+ /**
544+ * @param withRawThrowable
545+ * @since 1.5.7
546+ */
547+ public void setWithRawThrowable (boolean withRawThrowable ) {
548+ this .withRawThrowable = withRawThrowable ;
549+ }
550+
515551 public void setWithFormattedMessage (boolean withFormattedMessage ) {
516552 this .withFormattedMessage = withFormattedMessage ;
517553 }
518-
519554}
0 commit comments