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