繁体   English   中英

将异常与结构化参数一起记录

[英]Logging exceptions together with structured arguments

有谁知道记录异常和结构化参数的最佳实践是什么? 查看https://github.com/logstash/logstash-logback-encoder#customizing-stack-traces ,建议不要使用它们,但没有提供替代方案。

只需像通常使用 slf4j/logback记录异常一样记录异常 具体来说,提供异常作为日志语句的最后一个参数。

例子

// 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM