Bug 958596 - Allow TreeLog logging to be conditioned on a pref. r=Bas
☠☠ backed out by 9ad415f6d6cb ☠ ☠
authorBotond Ballo <botond@mozilla.com>
Wed, 22 Jan 2014 15:19:01 -0500
changeset 170759 c88e6d34fe9036a1d60ef5de5029f2c0f33f8c4b
parent 170758 eb4286cfa305fc518fa89bea0aa28ee93a1226f6
child 170760 f966e6a3d741f7b6859b71ce7451fc416728f32a
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersBas
bugs958596
milestone30.0a1
Bug 958596 - Allow TreeLog logging to be conditioned on a pref. r=Bas
gfx/2d/Logging.h
--- a/gfx/2d/Logging.h
+++ b/gfx/2d/Logging.h
@@ -157,41 +157,53 @@ const int INDENT_PER_LEVEL = 2;
 
 class TreeLog
 {
 public:
   TreeLog(const std::string& aPrefix = "")
         : mLog(LogOptions::NoNewline),
           mPrefix(aPrefix),
           mDepth(0),
-          mStartOfLine(true) {}
+          mStartOfLine(true),
+          mConditionedOnPref(false),
+          mPref(nullptr) {}
 
   template <typename T>
   TreeLog& operator<<(const T& aObject) {
+    if (mConditionedOnPref && !*mPref) {
+      return *this;
+    }
     if (mStartOfLine) {
       mLog << '[' << mPrefix << "] " << std::string(mDepth * INDENT_PER_LEVEL, ' ');
       mStartOfLine = false;
     }
     mLog << aObject;
     if (EndsInNewline(aObject)) {
       // Don't indent right here as the user may change the indent
       // between now and the first output to the next line.
       mLog.Flush();
       mStartOfLine = true;
     }
     return *this;
   }
 
   void IncreaseIndent() { ++mDepth; }
   void DecreaseIndent() { --mDepth; }
+
+  void ConditionOnPref(bool* aPref) {
+    mConditionedOnPref = true;
+    mPref = aPref;
+  }
 private:
   Log<LOG_DEBUG> mLog;
   std::string mPrefix;
   uint32_t mDepth;
   bool mStartOfLine;
+  bool mConditionedOnPref;
+  bool* mPref;
 
   template <typename T>
   static bool EndsInNewline(const T& aObject) {
     return false;
   }
 
   static bool EndsInNewline(const std::string& aString) {
     return !aString.empty() && aString[aString.length() - 1] == '\n';