Index: third_party/WebKit/Source/wtf/Assertions.h |
diff --git a/third_party/WebKit/Source/wtf/Assertions.h b/third_party/WebKit/Source/wtf/Assertions.h |
index 2c363f941fccb79e425c665803b6c4522c84e737..abeb98b4f70ed05788353003e84c072973200302 100644 |
--- a/third_party/WebKit/Source/wtf/Assertions.h |
+++ b/third_party/WebKit/Source/wtf/Assertions.h |
@@ -89,6 +89,51 @@ WTF_EXPORT void WTFGetBacktrace(void** stack, int* size); |
WTF_EXPORT void WTFReportBacktrace(int framesToShow = 31); |
WTF_EXPORT void WTFPrintBacktrace(void** stack, int size); |
+namespace WTF { |
+ |
+// ScopedLogger wraps log messages in parentheses, with indentation proportional |
+// to the number of instances. This makes it easy to see the flow of control in |
+// the output, particularly when instrumenting recursive functions. |
tkent
2016/03/28 23:16:30
Please add a comment that this class is not used i
skobes
2016/03/29 18:23:40
Done.
|
+class WTF_EXPORT ScopedLogger { |
+ WTF_MAKE_NONCOPYABLE(ScopedLogger); |
+public: |
+ // The first message is passed to the constructor. Additional messages for |
+ // the same scope can be added with log(). If condition is false, produce no |
+ // output and do not create a scope. |
+ ScopedLogger(bool condition, const char* format, ...) WTF_ATTRIBUTE_PRINTF(3, 4); |
+ ~ScopedLogger(); |
+ void log(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3); |
+ |
+private: |
+ friend class AssertionsTest; |
tkent
2016/03/28 23:16:30
Please use FRIEND_TEST_ALL_PREFIXES defined in bas
skobes
2016/03/29 18:23:40
Done.
|
+ using PrintFunctionPtr = void (*)(const char* format, va_list args); |
+ static void setPrintFuncForTests(PrintFunctionPtr p) { m_printFunc = p; } // Note: not thread safe. |
+ |
+ void init(const char* format, va_list args); |
+ void writeNewlineIfNeeded(); |
+ void indent(); |
+ void print(const char* format, ...); |
+ static ScopedLogger*& current(); |
+ |
+ ScopedLogger* const m_parent; |
+ bool m_multiline; // The ')' will go on the same line if there is only one entry. |
+ static PrintFunctionPtr m_printFunc; |
+}; |
+ |
+#if LOG_DISABLED |
tkent
2016/03/28 23:16:30
We'd like to remove LOG_DISABLED macro. Can you m
skobes
2016/03/29 18:23:40
That breaks blink_logging_always_on.
|
+#define WTF_CREATE_SCOPED_LOGGER(...) ((void) 0) |
+#define WTF_CREATE_SCOPED_LOGGER_IF(...) ((void) 0) |
+#define WTF_APPEND_SCOPED_LOGGER(...) ((void) 0) |
+#else |
+#define WTF_CREATE_SCOPED_LOGGER(name, ...) ScopedLogger name(true, __VA_ARGS__) |
tkent
2016/03/28 23:16:30
ScopedLogger class should be declared here to avoi
skobes
2016/03/29 18:23:40
Done.
|
+#define WTF_CREATE_SCOPED_LOGGER_IF(name, condition, ...) ScopedLogger name(condition, __VA_ARGS__) |
+#define WTF_APPEND_SCOPED_LOGGER(name, ...) (name.log(__VA_ARGS__)) |
+#endif |
+ |
+} // namespace WTF |
+ |
+using WTF::ScopedLogger; |
+ |
/* IMMEDIATE_CRASH() - Like CRASH() below but crashes in the fastest, simplest possible way with no attempt at logging. */ |
#ifndef IMMEDIATE_CRASH |
#if COMPILER(GCC) || COMPILER(CLANG) |