From: Kai Moritz Date: Tue, 20 Feb 2024 16:35:14 +0000 (+0100) Subject: feat: Added logging for io.projectreactor to `MongoDbStorageStrategy` X-Git-Tag: rebase--2024-02-22~1 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=dfbb212669e2e414857a5ab84f0be24ed6d5c876;p=demos%2Fkafka%2Fchat feat: Added logging for io.projectreactor to `MongoDbStorageStrategy` --- 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); } } diff --git a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java index 7566f521..f0f57283 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/InMemoryWithMongoDbStorageIT.java @@ -24,6 +24,7 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.time.Clock; +import java.util.logging.Level; @Testcontainers @@ -62,7 +63,11 @@ public class InMemoryWithMongoDbStorageIT extends AbstractInMemoryStorageIT ChatRoomRepository chatRoomRepository, MessageRepository messageRepository) { - return new MongoDbStorageStrategy(chatRoomRepository, messageRepository); + return new MongoDbStorageStrategy( + chatRoomRepository, + messageRepository, + Level.FINE, + true); } @Bean