From 639d2a9e831b16d193b7e0813cc24ff8abe415ac Mon Sep 17 00:00:00 2001
From: mbellgardt <bellgardt@vr.rwth-aachen.de>
Date: Tue, 26 Jan 2021 12:05:47 +0100
Subject: [PATCH] Add a Prefix to LogStreams to distinguish different streams
 in the same file.

---
 Source/UniversalLogging/Private/LogStream.cpp        | 12 +++++++++++-
 Source/UniversalLogging/Private/LogStream.h          |  4 ++++
 .../Private/UniLogBlueprintFunctionLibrary.cpp       |  3 ++-
 Source/UniversalLogging/Public/ILogStream.h          |  3 +++
 .../Public/UniLogBlueprintFunctionLibrary.h          |  2 +-
 5 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/Source/UniversalLogging/Private/LogStream.cpp b/Source/UniversalLogging/Private/LogStream.cpp
index fd9d6a7..c20b9d8 100644
--- a/Source/UniversalLogging/Private/LogStream.cpp
+++ b/Source/UniversalLogging/Private/LogStream.cpp
@@ -48,6 +48,16 @@ FString LogStreamImpl::GetFilename()
   return Filename;
 }
 
+void LogStreamImpl::SetPrefix(FString Prefix)
+{
+  MessagePrefix = Prefix;
+}
+
+FString LogStreamImpl::GetPrefix() const
+{
+  return MessagePrefix;
+}
+
 void LogStreamImpl::SetOnScreen(const bool Val)
 {
   bOnScreen = Val;
@@ -177,5 +187,5 @@ void LogStreamImpl::Write(const FString Text)
     return;
   if (!Log_File_Stream->GetIsOpen())
     Open();
-  Log_File_Stream->Write(Text);
+  Log_File_Stream->Write(MessagePrefix + Text);
 }
\ No newline at end of file
diff --git a/Source/UniversalLogging/Private/LogStream.h b/Source/UniversalLogging/Private/LogStream.h
index f63b3f1..ab28299 100644
--- a/Source/UniversalLogging/Private/LogStream.h
+++ b/Source/UniversalLogging/Private/LogStream.h
@@ -16,6 +16,9 @@ public:
   FString GetFilepath() override;
   FString GetFilename() override;
 
+  void SetPrefix(FString Prefix) override;
+  FString GetPrefix() const override;
+
   void SetOnScreen(const bool Val) override;
   bool GetOnScreen() const override;
   void SetOnScreenColor(const FColor Color) override;
@@ -48,6 +51,7 @@ public:
 private:
   const FString Filepath;
   const FString Filename;
+  FString MessagePrefix;
   bool bPer_Session;
 
   bool bOnScreen;
diff --git a/Source/UniversalLogging/Private/UniLogBlueprintFunctionLibrary.cpp b/Source/UniversalLogging/Private/UniLogBlueprintFunctionLibrary.cpp
index 7a9c745..da7f1f9 100644
--- a/Source/UniversalLogging/Private/UniLogBlueprintFunctionLibrary.cpp
+++ b/Source/UniversalLogging/Private/UniLogBlueprintFunctionLibrary.cpp
@@ -26,7 +26,7 @@ FString UUniLogBlueprintFunctionLibrary::GetSessionIdentifier()
 }
 
 void UUniLogBlueprintFunctionLibrary::NewLogStream(const FString StreamName, const FString Filepath,
-                                                   const FString Filename, bool bPer_Session, bool bOnScreen/* = false*/,
+                                                   const FString Filename, FString Prefix, bool bPer_Session, bool bOnScreen/* = false*/,
                                                    FColor OnScreenColor/* = FColor(0, 0, 255, 0)*/,
                                                    FColor OnScreenBackgroundColor, float OnScreenSize,
                                                    float OnScreenDuration,
@@ -36,6 +36,7 @@ void UUniLogBlueprintFunctionLibrary::NewLogStream(const FString StreamName, con
                                                    bool bLogOnScreenOnSlaves/* = false*/)
 {
   auto LogStream = UniLog.NewLogStream(StreamName, Filepath, Filename, bPer_Session, bLogOnMaster, bLogOnSlaves);
+  LogStream->SetPrefix(Prefix);
   LogStream->SetOnScreen(bOnScreen);
   LogStream->SetOnScreenColor(OnScreenColor);
   LogStream->SetOnScreenBackgroundColor(OnScreenBackgroundColor);
diff --git a/Source/UniversalLogging/Public/ILogStream.h b/Source/UniversalLogging/Public/ILogStream.h
index 3506362..49ef4d2 100644
--- a/Source/UniversalLogging/Public/ILogStream.h
+++ b/Source/UniversalLogging/Public/ILogStream.h
@@ -7,6 +7,9 @@ public:
   virtual FString GetFilename() = 0;
   virtual bool GetIsValid() = 0;
 
+  virtual void SetPrefix(FString Prefix) = 0;
+  virtual FString GetPrefix() const = 0;
+
   virtual void SetOnScreen(const bool Val) = 0;
   virtual bool GetOnScreen() const = 0;
   virtual void SetOnScreenColor(const FColor Color) = 0;
diff --git a/Source/UniversalLogging/Public/UniLogBlueprintFunctionLibrary.h b/Source/UniversalLogging/Public/UniLogBlueprintFunctionLibrary.h
index fd9c705..ce5d6e4 100644
--- a/Source/UniversalLogging/Public/UniLogBlueprintFunctionLibrary.h
+++ b/Source/UniversalLogging/Public/UniLogBlueprintFunctionLibrary.h
@@ -23,7 +23,7 @@ class UUniLogBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
     static FString GetSessionIdentifier();
 
   UFUNCTION(BlueprintCallable, Category = "UniLog")
-    static void NewLogStream(const FString StreamName, const FString Filepath, const FString Filename,
+    static void NewLogStream(const FString StreamName, const FString Filepath, const FString Filename, FString Prefix,
                              bool bPer_Session = false, bool bOnScreen = false,
                              FColor OnScreenColor = FColor(255, 255, 255, 255),
                              FColor OnScreenBackgroundColor = FColor(0, 0, 0, 128),
-- 
GitLab