SLF4J如何支持结构化日志记录 [英] How does SLF4J support structured logging

查看:73
本文介绍了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如何支持结构化日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆