Changeset 191474 in webkit
- Timestamp:
- Oct 22, 2015, 2:29:54 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
platform/Logging.cpp (modified) (1 diff)
-
platform/Logging.h (modified) (2 diffs)
-
platform/text/TextStream.cpp (modified) (3 diffs)
-
platform/text/TextStream.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r191473 r191474 1 2015-10-22 Simon Fraser <simon.fraser@apple.com> 2 3 Add ways to log to log channels via a functional syntax, and via a TextStream 4 https://bugs.webkit.org/show_bug.cgi?id=150472 5 6 Reviewed by Tim Horton. 7 8 Make it possible to write to a WTFLogChannel with a std::function that returns 9 a const char*, and with stream syntax. 10 11 Enhance TextStream to allow it to generate single-line output. 12 13 * platform/Logging.cpp: 14 (WebCore::logFunctionResult): 15 * platform/Logging.h: 16 * platform/text/TextStream.cpp: 17 (WebCore::TextStream::startGroup): 18 (WebCore::TextStream::endGroup): 19 (WebCore::TextStream::nextLine): 20 (WebCore::TextStream::writeIndent): 21 * platform/text/TextStream.h: 22 (WebCore::TextStream::TextStream): 23 1 24 2015-10-22 Alex Christensen <achristensen@webkit.org> 2 25 -
trunk/Source/WebCore/platform/Logging.cpp
r191450 r191474 83 83 #endif 84 84 85 void logFunctionResult(WTFLogChannel* channel, std::function<const char*()> function) 86 { 87 WTFLog(channel, "%s", function()); 85 88 } 86 89 90 } // namespace WebCore 91 87 92 #endif // !LOG_DISABLED -
trunk/Source/WebCore/platform/Logging.h
r191439 r191474 31 31 #include <wtf/Forward.h> 32 32 33 #if !LOG_DISABLED 33 namespace WebCore { 34 35 #if LOG_DISABLED 36 37 #define LOG_RESULT(channel, function) ((void)0) 38 #define LOG_WITH_STREAM(channel, commands) ((void)0) 39 40 #else 34 41 35 42 #ifndef LOG_CHANNEL_PREFIX 36 43 #define LOG_CHANNEL_PREFIX Log 37 44 #endif 38 39 namespace WebCore {40 45 41 46 #define WEBCORE_LOG_CHANNELS(M) \ … … 88 93 #undef DECLARE_LOG_CHANNEL 89 94 90 String logLevelString();91 bool isLogChannelEnabled(const String& name);92 WEBCORE_EXPORT void initializeLoggingChannelsIfNecessary();95 String logLevelString(); 96 bool isLogChannelEnabled(const String& name); 97 WEBCORE_EXPORT void initializeLoggingChannelsIfNecessary(); 93 98 #ifndef NDEBUG 94 void registerNotifyCallback(const String& notifyID, std::function<void()> callback);99 void registerNotifyCallback(const String& notifyID, std::function<void()> callback); 95 100 #endif 96 } 101 102 void logFunctionResult(WTFLogChannel*, std::function<const char*()>); 103 104 #define LOG_RESULT(channel, function) logFunctionResult(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), function) 105 106 #define LOG_WITH_STREAM(channel, commands) logFunctionResult(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), \ 107 [&]() { \ 108 TextStream stream(TextStream::LineMode::SingleLine); \ 109 commands; \ 110 return stream.release().utf8().data(); \ 111 }); 97 112 98 113 #endif // !LOG_DISABLED 99 114 115 } // namespace WebCore 116 100 117 #endif // Logging_h -
trunk/Source/WebCore/platform/text/TextStream.cpp
r191243 r191474 143 143 { 144 144 TextStream& ts = *this; 145 ts << "\n"; 146 ts.writeIndent(); 147 ts << "("; 148 ts.increaseIndent(); 145 146 if (m_multiLineMode) { 147 ts << "\n"; 148 ts.writeIndent(); 149 ts << "("; 150 ts.increaseIndent(); 151 } else 152 ts << " ("; 149 153 } 150 154 … … 153 157 TextStream& ts = *this; 154 158 ts << ")"; 155 ts.decreaseIndent(); 159 if (m_multiLineMode) 160 ts.decreaseIndent(); 156 161 } 157 162 … … 159 164 { 160 165 TextStream& ts = *this; 161 ts << "\n"; 162 ts.writeIndent(); 166 if (m_multiLineMode) { 167 ts << "\n"; 168 ts.writeIndent(); 169 } else 170 ts << " "; 163 171 } 164 172 165 173 void TextStream::writeIndent() 166 174 { 167 WebCore::writeIndent(*this, m_indent); 175 if (m_multiLineMode) 176 WebCore::writeIndent(*this, m_indent); 168 177 } 169 178 -
trunk/Source/WebCore/platform/text/TextStream.h
r191310 r191474 32 32 namespace WebCore { 33 33 34 class FloatPoint;35 class IntPoint;36 class LayoutPoint;37 class LayoutRect;38 34 class LayoutUnit; 39 35 40 // FIXME: this should move to platform/41 36 class TextStream { 42 37 public: … … 45 40 double value; 46 41 }; 42 43 enum class LineMode { SingleLine, MultipleLine }; 44 TextStream(LineMode lineMode = LineMode::MultipleLine) 45 : m_multiLineMode(lineMode == LineMode::MultipleLine) 46 { 47 } 47 48 48 49 WEBCORE_EXPORT TextStream& operator<<(bool); … … 101 102 StringBuilder m_text; 102 103 int m_indent { 0 }; 104 bool m_multiLineMode { true }; 103 105 }; 104 106
Note:
See TracChangeset
for help on using the changeset viewer.