How to print stack trace from logback custom layout?

ThrowableProxyConverter is the way to go to print the stack trace. Thus, the code you intend to use looks good. However, instead of writing a CustomLayout, you could adapt PatternLayout with custom converters. In the vast majority of cases, that is the easier/better option.


This might help you:

ch.qos.logback.classic.spi.ThrowableProxyUtil

StringBuffer sbuf = new StringBuffer();
....
IThrowableProxy throwbleProxy =  event.getThrowableProxy();
if (throwbleProxy != null) {
    String throwableStr = ThrowableProxyUtil.asString(throwbleProxy);
    sbuf.append(throwableStr);
    sbuf.append(CoreConstants.LINE_SEPARATOR);
}