Does anyone know what are best practices for logging exceptions together with structured arguments? Looking at https://github.com/logstash/logstash-logback-encoder#customizing-stack-traces, it is suggested to not use them but no alternative is provided.
Logging exceptions together with structured arguments
Asked Answered
Just log exceptions as you would normally log exceptions with slf4j/logback. Specifically, provide the exception as the last argument to the log statement.
Examples
// With no other arguments
logger.warn("Something bad happened", exception);
// With a regular (non-structured) argument
logger.warn("Something bad happened with {}", "foo", exception);
// With a structured argument
logger.warn("Something bad happened with {}", kv("foo", "bar"), exception);
It works, I made the mistake of putting the exception before the structured arguments and not tried the opposite. Thanks for the help! –
Industry
© 2022 - 2024 — McMap. All rights reserved.