Reputation: 89
I am using Spring Boot with Curator (https://github.com/spring-projects/spring-boot/tree/master/spring-boot-actuator). For monitoring I wan't to use the ELK stack. So I need to send my log files to LogStash, and the easiest way to do this is to use logback to preformat the logfile to json. By using the default logger - logstash-logback-encoder i can get the logfiles as json, but if the message in the log is also json, i do not get a big json file, i just get a field with the json and the message as a text field
Upvotes: 2
Views: 1486
Reputation: 89
The solution is use a different interface when sending logs.
You need to use the following import: import net.logstash.logback.argument.StructuredArguments._
This adds the option to pass arguments to the log file interface. The arguments are then added as a json object and not as a string field. In the code you then use the log as follows:
val res = RequestFactory.getRestContent(s"http://localhost:$serverPort/metrics") meticLogger.info("",raw("metric",res))
For further information see: http://javaandroidandrest.blogspot.co.il/2015/11/spring-boot-curator-and-elk.html
Upvotes: 2