Chromium Code Reviews| Index: third_party/WebKit/Source/wtf/Assertions.cpp |
| diff --git a/third_party/WebKit/Source/wtf/Assertions.cpp b/third_party/WebKit/Source/wtf/Assertions.cpp |
| index 3829cb304745c443ae4860ecf42266a0af71b6b9..6db714dd64acaccb8e843858a1bf77363c336d85 100644 |
| --- a/third_party/WebKit/Source/wtf/Assertions.cpp |
| +++ b/third_party/WebKit/Source/wtf/Assertions.cpp |
| @@ -231,6 +231,92 @@ FrameToNameScope::~FrameToNameScope() |
| } // anonymous namespace |
| +static const char kScopedLoggerIndent[] = " "; |
|
esprehn
2016/03/28 23:16:48
can we just add a method called printIndent() that
skobes
2016/03/29 18:23:40
Done.
|
| + |
| +ScopedLogger::ScopedLogger(bool condition, const char* format, ...) |
|
tkent
2016/03/28 23:16:30
The code should be wrapped with |namespace WTF|.
skobes
2016/03/29 18:23:40
Done.
|
| + : m_parent(condition ? current() : 0) |
| + , m_multiline(false) |
| +{ |
| + if (!condition) |
| + return; |
| + |
| + va_list args; |
| + va_start(args, format); |
| + init(format, args); |
| + va_end(args); |
| +} |
| + |
| +ScopedLogger::~ScopedLogger() |
| +{ |
| + if (current() == this) { |
| + if (m_multiline) |
| + indent(); |
| + else |
| + print(" "); |
| + print(")\n"); |
| + current() = m_parent; |
| + } |
| +} |
| + |
| +void ScopedLogger::init(const char* format, va_list args) |
| +{ |
| + current() = this; |
| + if (m_parent) |
| + m_parent->writeNewlineIfNeeded(); |
| + indent(); |
| + print("( "); |
| + m_printFunc(format, args); |
| +} |
| + |
| +void ScopedLogger::writeNewlineIfNeeded() |
| +{ |
| + if (!m_multiline) { |
| + print("\n"); |
| + m_multiline = true; |
| + } |
| +} |
| + |
| +void ScopedLogger::indent() |
| +{ |
| + if (m_parent) { |
| + m_parent->indent(); |
| + print(kScopedLoggerIndent); |
| + } |
| +} |
| + |
| +void ScopedLogger::log(const char* format, ...) |
| +{ |
| + if (current() != this) |
| + return; |
| + |
| + va_list args; |
| + va_start(args, format); |
| + |
| + writeNewlineIfNeeded(); |
| + indent(); |
| + print(kScopedLoggerIndent); |
| + m_printFunc(format, args); |
| + print("\n"); |
| + |
| + va_end(args); |
| +} |
| + |
| +void ScopedLogger::print(const char* format, ...) |
| +{ |
| + va_list args; |
| + va_start(args, format); |
| + m_printFunc(format, args); |
| + va_end(args); |
| +} |
| + |
| +ScopedLogger*& ScopedLogger::current() |
| +{ |
| + DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<ScopedLogger*>, ref, new ThreadSpecific<ScopedLogger*>); |
| + return *ref; |
| +} |
| + |
| +ScopedLogger::PrintFunctionPtr ScopedLogger::m_printFunc = vprintf_stderr_common; |
| + |
| void WTFPrintBacktrace(void** stack, int size) |
| { |
| for (int i = 0; i < size; ++i) { |