From 9489fde4a256970b3b51c0d1f8d4cef2c41187fa Mon Sep 17 00:00:00 2001 From: Byron Antak Date: Fri, 25 Oct 2024 14:21:07 +0100 Subject: [PATCH] Add configurable request logging --- .../mojito/security/RequestLoggingConfig.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 webapp/src/main/java/com/box/l10n/mojito/security/RequestLoggingConfig.java diff --git a/webapp/src/main/java/com/box/l10n/mojito/security/RequestLoggingConfig.java b/webapp/src/main/java/com/box/l10n/mojito/security/RequestLoggingConfig.java new file mode 100644 index 0000000000..6bc9dfe63c --- /dev/null +++ b/webapp/src/main/java/com/box/l10n/mojito/security/RequestLoggingConfig.java @@ -0,0 +1,29 @@ +package com.box.l10n.mojito.security; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.filter.CommonsRequestLoggingFilter; + +@Configuration +public class RequestLoggingConfig { + + @Value("${l10n.logging.includesQueryString:false}") + public boolean includesQueryString; + + @Value("${l10n.logging.includesHeader:false}") + public boolean includesHeader; + + @Bean + @ConditionalOnProperty(value = "l10n.logging.requests.enabled", havingValue = "true") + public CommonsRequestLoggingFilter logFilter() { + CommonsRequestLoggingFilter filter = new CommonsRequestLoggingFilter(); + filter.setIncludeQueryString(includesQueryString); + filter.setIncludePayload(true); + filter.setMaxPayloadLength(10000); + filter.setIncludeHeaders(includesHeader); + filter.setAfterMessagePrefix("REQUEST DATA: "); + return filter; + } +}