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..d5c4de4e370359c6acc0f28983ac7d6c86c28331 100644 |
--- a/third_party/WebKit/Source/wtf/Assertions.cpp |
+++ b/third_party/WebKit/Source/wtf/Assertions.cpp |
@@ -231,6 +231,101 @@ FrameToNameScope::~FrameToNameScope() |
} // anonymous namespace |
+#if !LOG_DISABLED |
+namespace WTF { |
+ |
+ScopedLogger::ScopedLogger(bool condition, const char* format, ...) |
+ : 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(); |
+ printIndent(); |
+ } |
+} |
+ |
+void ScopedLogger::log(const char* format, ...) |
+{ |
+ if (current() != this) |
+ return; |
+ |
+ va_list args; |
+ va_start(args, format); |
+ |
+ writeNewlineIfNeeded(); |
+ indent(); |
+ printIndent(); |
+ 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); |
+} |
+ |
+void ScopedLogger::printIndent() |
+{ |
+ print(" "); |
+} |
+ |
+ScopedLogger*& ScopedLogger::current() |
+{ |
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<ScopedLogger*>, ref, new ThreadSpecific<ScopedLogger*>); |
+ return *ref; |
+} |
+ |
+ScopedLogger::PrintFunctionPtr ScopedLogger::m_printFunc = vprintf_stderr_common; |
+ |
+} // namespace WTF |
+#endif // !LOG_DISABLED |
+ |
void WTFPrintBacktrace(void** stack, int size) |
{ |
for (int i = 0; i < size; ++i) { |