我正在使用 Spring Boot 和 Curator ( https://github.com/spring-projects/spring-boot/tree/master/spring-boot-actuator )。对于监控我不想使用 ELK 堆栈。因此,我需要将日志文件发送到 LogStash,最简单的方法是使用 logback 将日志文件预格式化为 json。通过使用默认记录器-logstash-logback-encoder,我可以获取json格式的日志文件,但是如果日志中的消息也是json,我不会得到一个大的json文件,我只是得到一个包含json和消息的字段作为文本字段
最佳答案
解决方案是在发送日志时使用不同的接口(interface)。
您需要使用以下导入: 导入net.logstash.logback.argument.StructuredArguments._
这添加了将参数传递到日志文件接口(interface)的选项。然后,参数将作为 json 对象而不是字符串字段添加。然后在代码中使用日志,如下所示:
val res = RequestFactory.getRestContent(s"http://localhost :$serverPort/metrics") meticLogger.info("",raw("metric",res))
欲了解更多信息,请参阅: http://javaandroidandrest.blogspot.co.il/2015/11/spring-boot-curator-and-elk.html
关于java - Spring BootP 的 JSON 格式日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33887589/