记录到JSON [英] Logging to JSON

查看:65
本文介绍了记录到JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有slf4j的实现以JSON格式登录.每个日志消息都是一个JSON对象,每行1个.

I'm wondering if there's an implementation of slf4j that logs into a JSON format. Where each log messages would be a JSON object, 1 per row.

例如日志文件的每一行如下所示:

e.g. each line of the log file would look like something this:

{"severity":"WARN", "ts":12345678, "host":"myhostname.com", "message":"Failed to do something"}

推荐答案

好吧,由于大多数答案都已经很老了,因此需要对该线程进行一些更新.所有现代Java日志库均支持开箱即用的json布局.使用log4j2,您甚至不需要任何其他库,只需在您的类路径中添加杰克逊(您很可能已经拥有了)即可.

Ok, this thread needs to be updated a bit since most of the answers are quite old. All modern java log liibraries support json layout out of the box. With log4j2 you don't even need any additional libs, just jackson in your classpath, which you most likely already have.

如果这还不够,您还可以查看此存储库: https://github.com/savoirtech/slf4j-json-logger

If this is not enough, you can also take a look at this repo: https://github.com/savoirtech/slf4j-json-logger

这篇关于记录到JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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