From b012ef4a0004a483fa325edf2ea05a4ab8fc54fe Mon Sep 17 00:00:00 2001 From: narwa Date: Sun, 8 Dec 2024 17:33:51 +0700 Subject: [PATCH] feat(LogbookConfig): use logbook's json formatter as sink Took 41 seconds --- .../configurations/LogbookConfig.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/dev/kons/kuenyawz/configurations/LogbookConfig.java diff --git a/src/main/java/dev/kons/kuenyawz/configurations/LogbookConfig.java b/src/main/java/dev/kons/kuenyawz/configurations/LogbookConfig.java new file mode 100644 index 00000000..4467774c --- /dev/null +++ b/src/main/java/dev/kons/kuenyawz/configurations/LogbookConfig.java @@ -0,0 +1,27 @@ +package dev.kons.kuenyawz.configurations; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.zalando.logbook.HttpLogFormatter; +import org.zalando.logbook.Sink; +import org.zalando.logbook.json.JsonHttpLogFormatter; +import org.zalando.logbook.logstash.LogstashLogbackSink; + +/** + * Configures the logstash to properly format the logbook logs. + * Without this, the JSON logs will escape the double quotes and unable + * to be parsed. + *

+ * + * Udemy Reference + */ +@Configuration +public class LogbookConfig { + + @Bean + public Sink logbookLogStash() { + HttpLogFormatter formatter = new JsonHttpLogFormatter(); + LogstashLogbackSink sink = new LogstashLogbackSink(formatter); + return sink; + } +}