Title: [191474] trunk/Source/WebCore
- Revision
- 191474
- Author
- simon.fra...@apple.com
- Date
- 2015-10-22 14:29:54 -0700 (Thu, 22 Oct 2015)
Log Message
Add ways to log to log channels via a functional syntax, and via a TextStream
https://bugs.webkit.org/show_bug.cgi?id=150472
Reviewed by Tim Horton.
Make it possible to write to a WTFLogChannel with a std::function that returns
a const char*, and with stream syntax.
Enhance TextStream to allow it to generate single-line output.
* platform/Logging.cpp:
(WebCore::logFunctionResult):
* platform/Logging.h:
* platform/text/TextStream.cpp:
(WebCore::TextStream::startGroup):
(WebCore::TextStream::endGroup):
(WebCore::TextStream::nextLine):
(WebCore::TextStream::writeIndent):
* platform/text/TextStream.h:
(WebCore::TextStream::TextStream):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (191473 => 191474)
--- trunk/Source/WebCore/ChangeLog 2015-10-22 21:17:59 UTC (rev 191473)
+++ trunk/Source/WebCore/ChangeLog 2015-10-22 21:29:54 UTC (rev 191474)
@@ -1,3 +1,26 @@
+2015-10-22 Simon Fraser <simon.fra...@apple.com>
+
+ Add ways to log to log channels via a functional syntax, and via a TextStream
+ https://bugs.webkit.org/show_bug.cgi?id=150472
+
+ Reviewed by Tim Horton.
+
+ Make it possible to write to a WTFLogChannel with a std::function that returns
+ a const char*, and with stream syntax.
+
+ Enhance TextStream to allow it to generate single-line output.
+
+ * platform/Logging.cpp:
+ (WebCore::logFunctionResult):
+ * platform/Logging.h:
+ * platform/text/TextStream.cpp:
+ (WebCore::TextStream::startGroup):
+ (WebCore::TextStream::endGroup):
+ (WebCore::TextStream::nextLine):
+ (WebCore::TextStream::writeIndent):
+ * platform/text/TextStream.h:
+ (WebCore::TextStream::TextStream):
+
2015-10-22 Alex Christensen <achristen...@webkit.org>
Progress towards CMake on Mac
Modified: trunk/Source/WebCore/platform/Logging.cpp (191473 => 191474)
--- trunk/Source/WebCore/platform/Logging.cpp 2015-10-22 21:17:59 UTC (rev 191473)
+++ trunk/Source/WebCore/platform/Logging.cpp 2015-10-22 21:29:54 UTC (rev 191474)
@@ -82,6 +82,11 @@
}
#endif
+void logFunctionResult(WTFLogChannel* channel, std::function<const char*()> function)
+{
+ WTFLog(channel, "%s", function());
}
+} // namespace WebCore
+
#endif // !LOG_DISABLED
Modified: trunk/Source/WebCore/platform/Logging.h (191473 => 191474)
--- trunk/Source/WebCore/platform/Logging.h 2015-10-22 21:17:59 UTC (rev 191473)
+++ trunk/Source/WebCore/platform/Logging.h 2015-10-22 21:29:54 UTC (rev 191474)
@@ -30,14 +30,19 @@
#include <wtf/Assertions.h>
#include <wtf/Forward.h>
-#if !LOG_DISABLED
+namespace WebCore {
+#if LOG_DISABLED
+
+#define LOG_RESULT(channel, function) ((void)0)
+#define LOG_WITH_STREAM(channel, commands) ((void)0)
+
+#else
+
#ifndef LOG_CHANNEL_PREFIX
#define LOG_CHANNEL_PREFIX Log
#endif
-namespace WebCore {
-
#define WEBCORE_LOG_CHANNELS(M) \
M(Animations) \
M(Archives) \
@@ -87,14 +92,26 @@
#undef DECLARE_LOG_CHANNEL
- String logLevelString();
- bool isLogChannelEnabled(const String& name);
- WEBCORE_EXPORT void initializeLoggingChannelsIfNecessary();
+String logLevelString();
+bool isLogChannelEnabled(const String& name);
+WEBCORE_EXPORT void initializeLoggingChannelsIfNecessary();
#ifndef NDEBUG
- void registerNotifyCallback(const String& notifyID, std::function<void()> callback);
+void registerNotifyCallback(const String& notifyID, std::function<void()> callback);
#endif
-}
+void logFunctionResult(WTFLogChannel*, std::function<const char*()>);
+
+#define LOG_RESULT(channel, function) logFunctionResult(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), function)
+
+#define LOG_WITH_STREAM(channel, commands) logFunctionResult(&JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, channel), \
+ [&]() { \
+ TextStream stream(TextStream::LineMode::SingleLine); \
+ commands; \
+ return stream.release().utf8().data(); \
+ });
+
#endif // !LOG_DISABLED
+} // namespace WebCore
+
#endif // Logging_h
Modified: trunk/Source/WebCore/platform/text/TextStream.cpp (191473 => 191474)
--- trunk/Source/WebCore/platform/text/TextStream.cpp 2015-10-22 21:17:59 UTC (rev 191473)
+++ trunk/Source/WebCore/platform/text/TextStream.cpp 2015-10-22 21:29:54 UTC (rev 191474)
@@ -142,29 +142,38 @@
void TextStream::startGroup()
{
TextStream& ts = *this;
- ts << "\n";
- ts.writeIndent();
- ts << "(";
- ts.increaseIndent();
+
+ if (m_multiLineMode) {
+ ts << "\n";
+ ts.writeIndent();
+ ts << "(";
+ ts.increaseIndent();
+ } else
+ ts << " (";
}
void TextStream::endGroup()
{
TextStream& ts = *this;
ts << ")";
- ts.decreaseIndent();
+ if (m_multiLineMode)
+ ts.decreaseIndent();
}
void TextStream::nextLine()
{
TextStream& ts = *this;
- ts << "\n";
- ts.writeIndent();
+ if (m_multiLineMode) {
+ ts << "\n";
+ ts.writeIndent();
+ } else
+ ts << " ";
}
void TextStream::writeIndent()
{
- WebCore::writeIndent(*this, m_indent);
+ if (m_multiLineMode)
+ WebCore::writeIndent(*this, m_indent);
}
void writeIndent(TextStream& ts, int indent)
Modified: trunk/Source/WebCore/platform/text/TextStream.h (191473 => 191474)
--- trunk/Source/WebCore/platform/text/TextStream.h 2015-10-22 21:17:59 UTC (rev 191473)
+++ trunk/Source/WebCore/platform/text/TextStream.h 2015-10-22 21:29:54 UTC (rev 191474)
@@ -31,19 +31,20 @@
namespace WebCore {
-class FloatPoint;
-class IntPoint;
-class LayoutPoint;
-class LayoutRect;
class LayoutUnit;
-// FIXME: this should move to platform/
class TextStream {
public:
struct FormatNumberRespectingIntegers {
FormatNumberRespectingIntegers(double number) : value(number) { }
double value;
};
+
+ enum class LineMode { SingleLine, MultipleLine };
+ TextStream(LineMode lineMode = LineMode::MultipleLine)
+ : m_multiLineMode(lineMode == LineMode::MultipleLine)
+ {
+ }
WEBCORE_EXPORT TextStream& operator<<(bool);
WEBCORE_EXPORT TextStream& operator<<(int);
@@ -100,6 +101,7 @@
private:
StringBuilder m_text;
int m_indent { 0 };
+ bool m_multiLineMode { true };
};
template<typename Item>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes