Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1360)

Unified Diff: third_party/WebKit/Source/wtf/Assertions.cpp

Issue 1840693002: Restore ScopedLogger and add documentation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/Assertions.h ('k') | third_party/WebKit/Source/wtf/AssertionsTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « third_party/WebKit/Source/wtf/Assertions.h ('k') | third_party/WebKit/Source/wtf/AssertionsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698