记录异常以及结构化参数

问题描述 投票:0回答:1

有人知道将异常与结构化参数一起记录的最佳做法是什么?查看https://github.com/logstash/logstash-logback-encoder#customizing-stack-traces,建议不要使用它们,但没有替代方法。

java slf4j logstash-logback-encoder
1个回答
0
投票

只需像normally log exceptions with slf4j/logback一样记录异常。具体来说,将异常作为log语句的最后一个参数提供。

示例

// 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);
© www.soinside.com 2019 - 2024. All rights reserved.