Search code examples
javalogstash

Logging stack trace in log appender


I would like to log the exception stack trace in stack-trace field of logstash log appender instead of being inside the message field

public void exceptionsCatcher(JoinPoint joinPoint, RuntimeException e) {
    ...
    log.error("exception  : {} ", e);

    ...
}

I searched throw community and just found solution with grok to filter out stack-trace from message field, what i would like is to set it at stack-trace field in application level and not in logstash filter .


Solution

  • You don't need extra configuration to do so just use proper overloaded method of your log provider, for example

        public void exceptionsCatcher(JoinPoint joinPoint, RuntimeException e) {
        ...
        log.error("exception : {} " + " some message description perhaps {}",
                e.getLocalizedMessage(), e.getMessage(), e);
        ...
    }
    

    The third marker will ingest stack trace into stack-trace attribute, find more about other overloaded methods in here.