From 2800b80bb0a02feb70ab9d0c804b2fcc9915f479 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 20 Feb 2024 12:48:40 +0100 Subject: [PATCH] feat: Introduced config-parameters for the `io.projectreactor`-logging --- .../chat/backend/ChatBackendProperties.java | 9 ++++++++ .../backend/api/ChatBackendController.java | 21 +++++++++++++++---- .../files/FilesStorageConfiguration.java | 4 +++- .../storage/files/FilesStorageStrategy.java | 18 +++++++++------- .../backend/InMemoryWithFilesStorageIT.java | 5 ++++- .../inmemory/ShardedChatHomeServiceTest.java | 5 ++++- .../inmemory/SimpleChatHomeServiceTest.java | 5 ++++- 7 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendProperties.java b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendProperties.java index 9a73f6f1..df4d1cd7 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendProperties.java +++ b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendProperties.java @@ -6,6 +6,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import java.net.URI; import java.nio.file.Paths; +import java.util.logging.Level; @ConfigurationProperties("chat.backend") @@ -19,6 +20,7 @@ public class ChatBackendProperties private ServiceType services = ServiceType.inmemory; private InMemoryServicesProperties inmemory = new InMemoryServicesProperties(); private KafkaServicesProperties kafka = new KafkaServicesProperties(); + private ProjectreactorProperties projectreactor = new ProjectreactorProperties(); @Getter @@ -47,6 +49,13 @@ public class ChatBackendProperties private String haproxyMap = "/usr/local/etc/haproxy/sharding.map"; } + @Getter + @Setter + public static class ProjectreactorProperties + { + private Level loggingLevel = Level.FINE; + private boolean showOperatorLine = true; + } public enum ServiceType { inmemory, kafka } public enum StorageStrategyType { none, files, mongodb } public enum ShardingStrategyType { none, kafkalike } diff --git a/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java b/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java index 1a8711a0..47ae6a5d 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java +++ b/src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java @@ -1,9 +1,9 @@ package de.juplo.kafka.chat.backend.api; +import de.juplo.kafka.chat.backend.ChatBackendProperties; import de.juplo.kafka.chat.backend.domain.ChatHomeService; import de.juplo.kafka.chat.backend.domain.ChatRoomData; import de.juplo.kafka.chat.backend.implementation.StorageStrategy; -import lombok.RequiredArgsConstructor; import org.springframework.http.codec.ServerSentEvent; import org.springframework.web.bind.annotation.*; import reactor.core.publisher.Flux; @@ -14,11 +14,24 @@ import java.util.logging.Level; @RestController -@RequiredArgsConstructor public class ChatBackendController { private final ChatHomeService chatHomeService; private final StorageStrategy storageStrategy; + private final Level loggingLevel; + private final boolean showOperatorLine; + + + public ChatBackendController( + ChatHomeService chatHomeService, + StorageStrategy storageStrategy, + ChatBackendProperties properties) + { + this.chatHomeService = chatHomeService; + this.storageStrategy = storageStrategy; + this.loggingLevel = properties.getProjectreactor().getLoggingLevel(); + this.showOperatorLine = properties.getProjectreactor().isShowOperatorLine(); + } @PostMapping("create") @@ -121,8 +134,8 @@ public class ChatBackendController .listen() .log( ChatBackendController.class.getSimpleName(), - Level.FINE, - true) + loggingLevel, + showOperatorLine) .map(message -> MessageTo.from(message)) .map(messageTo -> ServerSentEvent diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageConfiguration.java index 75487279..630c1fa9 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageConfiguration.java @@ -34,6 +34,8 @@ public class FilesStorageConfiguration return new FilesStorageStrategy( Paths.get(properties.getInmemory().getStorageDirectory()), shardingStrategy, - mapper); + mapper, + properties.getProjectreactor().getLoggingLevel(), + properties.getProjectreactor().isShowOperatorLine()); } } diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java index fd8939b6..aaa61598 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java @@ -33,6 +33,8 @@ public class FilesStorageStrategy implements StorageStrategy private final Path storagePath; private final ShardingStrategy shardingStrategy; private final ObjectMapper mapper; + private final Level loggingLevel; + private final boolean showOperatorLine; @Override @@ -52,8 +54,8 @@ public class FilesStorageStrategy implements StorageStrategy return chatRoomInfoFlux .log( FilesStorageStrategy.class.getSimpleName(), - Level.FINE, - true) + loggingLevel, + showOperatorLine) .doFirst(() -> { try @@ -106,8 +108,8 @@ public class FilesStorageStrategy implements StorageStrategy .from(new JsonFilePublisher(chatroomsPath(), mapper, type)) .log( FilesStorageStrategy.class.getSimpleName(), - Level.FINE, - true) + loggingLevel, + showOperatorLine) .map(chatRoomInfoTo -> { UUID chatRoomId = chatRoomInfoTo.getId(); @@ -145,8 +147,8 @@ public class FilesStorageStrategy implements StorageStrategy return messageFlux .log( FilesStorageStrategy.class.getSimpleName(), - Level.FINE, - true) + loggingLevel, + showOperatorLine) .doFirst(() -> { try @@ -199,8 +201,8 @@ public class FilesStorageStrategy implements StorageStrategy .from(new JsonFilePublisher(chatroomPath(chatRoomId), mapper, type)) .log( FilesStorageStrategy.class.getSimpleName(), - Level.FINE, - true) + loggingLevel, + showOperatorLine) .map(MessageTo::toMessage); } diff --git a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java index 19e3cc1a..78f46250 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java @@ -13,6 +13,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Clock; +import java.util.logging.Level; @Slf4j @@ -33,7 +34,9 @@ public class InMemoryWithFilesStorageIT extends AbstractInMemoryStorageIT storageStrategy = new FilesStorageStrategy( path, chatRoomId -> 0, - mapper); + mapper, + Level.FINE, + true); } diff --git a/src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/ShardedChatHomeServiceTest.java b/src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/ShardedChatHomeServiceTest.java index 8ed18448..8e21c5f0 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/ShardedChatHomeServiceTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/ShardedChatHomeServiceTest.java @@ -12,6 +12,7 @@ import org.springframework.context.annotation.Bean; import java.net.URI; import java.nio.file.Paths; import java.time.Clock; +import java.util.logging.Level; import java.util.stream.IntStream; public class ShardedChatHomeServiceTest extends ChatHomeServiceWithShardsTest @@ -55,7 +56,9 @@ public class ShardedChatHomeServiceTest extends ChatHomeServiceWithShardsTest return new FilesStorageStrategy( Paths.get("target", "test-classes", "data", "files"), new KafkaLikeShardingStrategy(NUM_SHARDS), - objectMapper); + objectMapper, + Level.FINE, + true); } @Bean diff --git a/src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeServiceTest.java b/src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeServiceTest.java index b967df82..e57d06dc 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeServiceTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeServiceTest.java @@ -10,6 +10,7 @@ import org.springframework.context.annotation.Bean; import java.nio.file.Paths; import java.time.Clock; +import java.util.logging.Level; public class SimpleChatHomeServiceTest extends ChatHomeServiceTest @@ -36,7 +37,9 @@ public class SimpleChatHomeServiceTest extends ChatHomeServiceTest return new FilesStorageStrategy( Paths.get("target", "test-classes", "data", "files"), chatRoomId -> 0, - objectMapper); + objectMapper, + Level.FINE, + true); } @Bean -- 2.20.1