Bug 958596 - Allow TreeLog logging to be conditioned on a pref. r=Bas

This commit is contained in:
Botond Ballo 2014-01-22 15:19:01 -05:00
Родитель ecd9186cdc
Коммит f04e527185
1 изменённых файлов: 13 добавлений и 1 удалений

Просмотреть файл

@ -162,10 +162,15 @@ public:
: 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;
@ -182,11 +187,18 @@ public:
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) {