From d4f83979aaa9cb12ecf97a428f8f04f35ae3547d Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Tue, 20 Feb 2024 17:35:14 +0100 Subject: [PATCH] feat: Added logging for io.projectreactor to `MongoDbStorageStrategy` --- .../mongodb/MongoDbStorageConfiguration.java | 10 ++++++++-- .../mongodb/MongoDbStorageStrategy.java | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageConfiguration.java index 1b5803ac..7c5d9cb5 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageConfiguration.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageConfiguration.java @@ -1,5 +1,6 @@ package de.juplo.kafka.chat.backend.storage.mongodb; +import de.juplo.kafka.chat.backend.ChatBackendProperties; import de.juplo.kafka.chat.backend.implementation.ShardingStrategy; import de.juplo.kafka.chat.backend.implementation.StorageStrategy; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -17,8 +18,13 @@ public class MongoDbStorageConfiguration @Bean public StorageStrategy storageStrategy( ChatRoomRepository chatRoomRepository, - MessageRepository messageRepository) + MessageRepository messageRepository, + ChatBackendProperties properties) { - return new MongoDbStorageStrategy(chatRoomRepository, messageRepository); + return new MongoDbStorageStrategy( + chatRoomRepository, + messageRepository, + properties.getProjectreactor().getLoggingLevel(), + properties.getProjectreactor().isShowOperatorLine()); } } diff --git a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java index fb040395..81696450 100644 --- a/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java +++ b/src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java @@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j; import reactor.core.publisher.Flux; import java.util.UUID; +import java.util.logging.Level; @RequiredArgsConstructor @@ -16,12 +17,19 @@ public class MongoDbStorageStrategy implements StorageStrategy { private final ChatRoomRepository chatRoomRepository; private final MessageRepository messageRepository; + private final String loggingCategory = MongoDbStorageStrategy.class.getSimpleName(); + private final Level loggingLevel; + private final boolean showOperatorLine; @Override public Flux writeChatRoomInfo(Flux chatRoomInfoFlux) { return chatRoomInfoFlux + .log( + loggingCategory, + loggingLevel, + showOperatorLine) .map(ChatRoomTo::from) .map(chatRoomRepository::save) .map(ChatRoomTo::toChatRoomInfo); @@ -32,6 +40,10 @@ public class MongoDbStorageStrategy implements StorageStrategy { return Flux .fromIterable(chatRoomRepository.findAll()) + .log( + loggingCategory, + loggingLevel, + showOperatorLine) .map(ChatRoomTo::toChatRoomInfo); } @@ -39,6 +51,10 @@ public class MongoDbStorageStrategy implements StorageStrategy public Flux writeChatRoomData(UUID chatRoomId, Flux messageFlux) { return messageFlux + .log( + loggingCategory, + loggingLevel, + showOperatorLine) .map(message -> MessageTo.from(chatRoomId, message)) .map(messageRepository::save) .map(MessageTo::toMessage); @@ -49,6 +65,10 @@ public class MongoDbStorageStrategy implements StorageStrategy { return Flux .fromIterable(messageRepository.findByChatRoomIdOrderBySerialAsc(chatRoomId.toString())) + .log( + loggingCategory, + loggingLevel, + showOperatorLine) .map(MessageTo::toMessage); } } -- 2.20.1