changeset 3589:a648c2d67a65

merge
author Alain Mazy <alain@mazy.be>
date Thu, 19 Dec 2019 22:17:24 +0100
parents eb48adfd931e (diff) 76b3228f99b0 (current diff)
children d5740d3b1d67
files
diffstat 1 files changed, 19 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/Resources/Samples/CppHelpers/Logging/ILogger.h	Thu Dec 05 16:21:41 2019 +0100
+++ b/Resources/Samples/CppHelpers/Logging/ILogger.h	Thu Dec 19 22:17:24 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_);
     }
 
   };