SLF4J如何支持结构化日志记录

编程入门 行业动态 更新时间:2024-10-24 23:19:20
本文介绍了SLF4J如何支持结构化日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

任何人都知道SLF4J通常是如何实现结构化日志的吗?

Anyone knows how structured logging is usually implemented with SLF4J?

是否已经有开放源代码可以处理此问题?

Is there any open source already out there handling this?

推荐答案

如果将SLF4J与Logback和Logstash结合使用,则 StructuredArguments 支持结构化日志记录.您可以在Github上的 logstash logback编码器页面上找到有关此文档的文档.

If you use SLF4J in conjunction with Logback and Logstash, structured logging is supported with StructuredArguments. You can find documentation about this on the logstash logback encoder page on Github.

一个简单的例子.此日志行.

A simple example of how it works. This log line..

log.debug("Retrieved file {}", StructuredArguments.value("filename", upload.getOriginalFilename()))

..产生以下log json输出:

..yields the following log json output:

{ "filename": "simple.zip", "@timestamp": "2019-02-12T14:31:31.631+00:00", "severity": "DEBUG", "service": "upload", "thread": "http-nio-9091-exec-1", "logger": "some.great.ClassName", "message": "Retrieved file simple.zip" }

更多推荐

SLF4J如何支持结构化日志记录

本文发布于:2023-11-25 04:00:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628233.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:结构化   日志   SLF4J

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!