feat: Introduced config-parameters for the `io.projectreactor`-logging
authorKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 11:48:40 +0000 (12:48 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 14:28:35 +0000 (15:28 +0100)
src/main/java/de/juplo/kafka/chat/backend/ChatBackendProperties.java
src/main/java/de/juplo/kafka/chat/backend/api/ChatBackendController.java
src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageConfiguration.java
src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java
src/test/java/de/juplo/kafka/chat/backend/InMemoryWithFilesStorageIT.java
src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/ShardedChatHomeServiceTest.java
src/test/java/de/juplo/kafka/chat/backend/implementation/inmemory/SimpleChatHomeServiceTest.java

index 9a73f6f..df4d1cd 100644 (file)
@@ -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 }
index 1a8711a..47ae6a5 100644 (file)
@@ -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
index 7548727..630c1fa 100644 (file)
@@ -34,6 +34,8 @@ public class FilesStorageConfiguration
     return new FilesStorageStrategy(
         Paths.get(properties.getInmemory().getStorageDirectory()),
         shardingStrategy,
-        mapper);
+        mapper,
+        properties.getProjectreactor().getLoggingLevel(),
+        properties.getProjectreactor().isShowOperatorLine());
   }
 }
index fd8939b..aaa6159 100644 (file)
@@ -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<ChatRoomInfoTo>(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<MessageTo>(chatroomPath(chatRoomId), mapper, type))
         .log(
             FilesStorageStrategy.class.getSimpleName(),
-            Level.FINE,
-            true)
+            loggingLevel,
+            showOperatorLine)
         .map(MessageTo::toMessage);
   }
 
index 19e3cc1..78f4625 100644 (file)
@@ -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);
   }
 
 
index 8ed1844..8e21c5f 100644 (file)
@@ -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
index b967df8..e57d06d 100644 (file)
@@ -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