refactor: DRY for logging-category from io.projectreactor
authorKai Moritz <kai@juplo.de>
Tue, 20 Feb 2024 16:32:54 +0000 (17:32 +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/api/ChatBackendController.java
src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java

index 47ae6a5..6c7cff7 100644 (file)
@@ -18,6 +18,7 @@ public class ChatBackendController
 {
   private final ChatHomeService chatHomeService;
   private final StorageStrategy storageStrategy;
+  private final String loggingCategory = ChatBackendController.class.getSimpleName();
   private final Level loggingLevel;
   private final boolean showOperatorLine;
 
@@ -133,7 +134,7 @@ public class ChatBackendController
     return chatRoomData
         .listen()
         .log(
-            ChatBackendController.class.getSimpleName(),
+            loggingCategory,
             loggingLevel,
             showOperatorLine)
         .map(message -> MessageTo.from(message))
index aaa6159..7c1fef0 100644 (file)
@@ -33,6 +33,7 @@ public class FilesStorageStrategy implements StorageStrategy
   private final Path storagePath;
   private final ShardingStrategy shardingStrategy;
   private final ObjectMapper mapper;
+  private final String loggingCategory = FilesStorageStrategy.class.getSimpleName();
   private final Level loggingLevel;
   private final boolean showOperatorLine;
 
@@ -53,7 +54,7 @@ public class FilesStorageStrategy implements StorageStrategy
 
       return chatRoomInfoFlux
           .log(
-              FilesStorageStrategy.class.getSimpleName(),
+              loggingCategory,
               loggingLevel,
               showOperatorLine)
           .doFirst(() ->
@@ -107,7 +108,7 @@ public class FilesStorageStrategy implements StorageStrategy
     return Flux
         .from(new JsonFilePublisher<ChatRoomInfoTo>(chatroomsPath(), mapper, type))
         .log(
-            FilesStorageStrategy.class.getSimpleName(),
+            loggingCategory,
             loggingLevel,
             showOperatorLine)
         .map(chatRoomInfoTo ->
@@ -146,7 +147,7 @@ public class FilesStorageStrategy implements StorageStrategy
 
       return messageFlux
           .log(
-              FilesStorageStrategy.class.getSimpleName(),
+              loggingCategory,
               loggingLevel,
               showOperatorLine)
           .doFirst(() ->
@@ -200,7 +201,7 @@ public class FilesStorageStrategy implements StorageStrategy
     return Flux
         .from(new JsonFilePublisher<MessageTo>(chatroomPath(chatRoomId), mapper, type))
         .log(
-            FilesStorageStrategy.class.getSimpleName(),
+            loggingCategory,
             loggingLevel,
             showOperatorLine)
         .map(MessageTo::toMessage);