feat: Added logging for io.projectreactor to `MongoDbStorageStrategy`
authorKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 16:35:14 +0000 (17:35 +0100)
committerKai Moritz <kai@juplo.de>
Thu, 22 Feb 2024 15:54:48 +0000 (16:54 +0100)
src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/storage/mongodb/MongoDbStorageStrategy.java

index 1b5803a..7c5d9cb 100644 (file)
@@ -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());
   }
 }
index fb04039..8169645 100644 (file)
@@ -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<ChatRoomInfo> writeChatRoomInfo(Flux<ChatRoomInfo> 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<Message> writeChatRoomData(UUID chatRoomId, Flux<Message> 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);
   }
 }