changeset 3588:eb48adfd931e

forceLogContextChanges
author Alain Mazy <alain@mazy.be>
date Thu, 19 Dec 2019 22:16:49 +0100
parents 5f1b1a8b2c28
children a648c2d67a65
files Resources/Samples/CppHelpers/Logging/ILogger.h
diffstat 1 files changed, 19 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/Samples/CppHelpers/Logging/ILogger.h	Mon Nov 25 05:41:28 2019 +0100
+++ b/Resources/Samples/CppHelpers/Logging/ILogger.h	Thu Dec 19 22:16:49 2019 +0100
@@ -25,9 +25,9 @@
     virtual void Error(const char* message) = 0;
     virtual void Error(const std::string& message) = 0;
 
-    virtual void EnterContext(const char* message) = 0;
-    virtual void EnterContext(const std::string& message) = 0;
-    virtual void LeaveContext() = 0;
+    virtual void EnterContext(const char* message, bool forceLogContextChange = false) = 0;
+    virtual void EnterContext(const std::string& message, bool forceLogContextChange = false) = 0;
+    virtual void LeaveContext(bool forceLogContextChange = false) = 0;
   };
 
 
@@ -55,12 +55,12 @@
       logContextChanges_ = enable;
     }
 
-    virtual void EnterContext(const char* message)
+    virtual void EnterContext(const char* message, bool forceLogContextChange = false)
     {
-      EnterContext(std::string(message));
+      EnterContext(std::string(message), forceLogContextChange);
     }
 
-    virtual void EnterContext(const std::string& message)
+    virtual void EnterContext(const std::string& message, bool forceLogContextChange = false)
     {
       if (!contexts_.get())
       {
@@ -68,15 +68,15 @@
       }
       contexts_->push_back(message);
 
-      if (logContextChanges_)
+      if (logContextChanges_ || forceLogContextChange)
       {
         Info(".. entering");
       }
     }
 
-    virtual void LeaveContext()
+    virtual void LeaveContext(bool forceLogContextChange = false)
     {
-      if (logContextChanges_)
+      if (logContextChanges_ || forceLogContextChange)
       {
         Info(".. leaving");
       }
@@ -128,22 +128,25 @@
   class LogContext
   {
     ILogger* logger_;
+    bool     forceLogContextChange_;
   public:
-    LogContext(ILogger* logger, const char* context) :
-      logger_(logger)
+    LogContext(ILogger* logger, const char* context, bool forceLogContextChange = false) :
+      logger_(logger),
+      forceLogContextChange_(forceLogContextChange)
     {
-      logger_->EnterContext(context);
+      logger_->EnterContext(context, forceLogContextChange_);
     }
 
-    LogContext(ILogger* logger, const std::string& context) :
-      logger_(logger)
+    LogContext(ILogger* logger, const std::string& context, bool forceLogContextChange = false) :
+      logger_(logger),
+      forceLogContextChange_(forceLogContextChange)
     {
-      logger_->EnterContext(context);
+      logger_->EnterContext(context, forceLogContextChange_);
     }
 
     ~LogContext()
     {
-      logger_->LeaveContext();
+      logger_->LeaveContext(forceLogContextChange_);
     }
 
   };