Diff
Modified: trunk/Source/WebCore/PAL/ChangeLog (221094 => 221095)
--- trunk/Source/WebCore/PAL/ChangeLog 2017-08-23 19:50:42 UTC (rev 221094)
+++ trunk/Source/WebCore/PAL/ChangeLog 2017-08-23 20:01:59 UTC (rev 221095)
@@ -1,3 +1,25 @@
+2017-08-23 Eric Carlson <[email protected]>
+
+ Platform code should be able to safely log in release builds
+ https://bugs.webkit.org/show_bug.cgi?id=175854
+ <rdar://problem/34022930>
+
+ Reviewed by Jer Noble.
+
+ * PAL.xcodeproj/project.pbxproj:
+ * pal/Logger.h: Added.
+ (PAL::Logger::create):
+ (PAL::Logger::error const):
+ (PAL::Logger::warning const):
+ (PAL::Logger::notice const):
+ (PAL::Logger::info const):
+ (PAL::Logger::debug const):
+ (PAL::Logger::willLog const):
+ (PAL::Logger::enabled const):
+ (PAL::Logger::setEnabled):
+ (PAL::Logger::Logger):
+ (PAL::Logger::log):
+
2017-08-21 Yoshiaki Jitsukawa <[email protected]>
[PAL] Move spi/mac directory into PAL
Modified: trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj (221094 => 221095)
--- trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj 2017-08-23 19:50:42 UTC (rev 221094)
+++ trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj 2017-08-23 20:01:59 UTC (rev 221095)
@@ -21,6 +21,7 @@
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
+ 0708AC331F4C874B001F788F /* Logger.h in Headers */ = {isa = PBXBuildFile; fileRef = 0708AC321F4C874A001F788F /* Logger.h */; };
0C2D9E731EEF5AF600DBC317 /* ExportMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 0C2D9E721EEF5AF600DBC317 /* ExportMacros.h */; };
0C2DA06D1F33CA8400DBC317 /* CFLocaleSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 0C2DA0671F33CA8400DBC317 /* CFLocaleSPI.h */; };
0C2DA06E1F33CA8400DBC317 /* CFNetworkConnectionCacheSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 0C2DA0681F33CA8400DBC317 /* CFNetworkConnectionCacheSPI.h */; };
@@ -125,6 +126,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
+ 0708AC321F4C874A001F788F /* Logger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Logger.h; sourceTree = "<group>"; };
0C2D9E721EEF5AF600DBC317 /* ExportMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExportMacros.h; sourceTree = "<group>"; };
0C2DA0671F33CA8400DBC317 /* CFLocaleSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CFLocaleSPI.h; path = spi/cf/CFLocaleSPI.h; sourceTree = "<group>"; };
0C2DA0681F33CA8400DBC317 /* CFNetworkConnectionCacheSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CFNetworkConnectionCacheSPI.h; path = spi/cf/CFNetworkConnectionCacheSPI.h; sourceTree = "<group>"; };
@@ -380,6 +382,7 @@
A3788E9F1F05B7CE00679425 /* system */,
A30D411D1F0DD0AC00B71954 /* text */,
0C2D9E721EEF5AF600DBC317 /* ExportMacros.h */,
+ 0708AC321F4C874A001F788F /* Logger.h */,
A3C66CDA1F462D6A009E6EE9 /* SessionID.cpp */,
A3C66CDB1F462D6A009E6EE9 /* SessionID.h */,
);
@@ -503,6 +506,7 @@
A30D41211F0DD0EA00B71954 /* KillRing.h in Headers */,
0C5AF91C1F43A4C7002EAC02 /* LaunchServicesSPI.h in Headers */,
0C2DA1471F3BEB4900DBC317 /* LinkPresentationSPI.h in Headers */,
+ 0708AC331F4C874B001F788F /* Logger.h in Headers */,
0C77858B1F45130F00F4EBB6 /* LookupSPI.h in Headers */,
0C2DA1481F3BEB4900DBC317 /* MachVMSPI.h in Headers */,
0C5AF91D1F43A4C7002EAC02 /* MediaPlayerSPI.h in Headers */,
Added: trunk/Source/WebCore/PAL/pal/Logger.h (0 => 221095)
--- trunk/Source/WebCore/PAL/pal/Logger.h (rev 0)
+++ trunk/Source/WebCore/PAL/pal/Logger.h 2017-08-23 20:01:59 UTC (rev 221095)
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/Assertions.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace PAL {
+
+class Logger : public RefCounted<Logger> {
+ WTF_MAKE_NONCOPYABLE(Logger);
+public:
+ static Ref<Logger> create(const void* owner)
+ {
+ return adoptRef(*new Logger(owner));
+ }
+
+ template<typename... Arguments>
+ inline void error(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const
+ {
+ if (!willLog(channel, WTFLogLevelError))
+ return;
+
+ log(channel, format, arguments...);
+ }
+
+ template<typename... Arguments>
+ inline void warning(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const
+ {
+ if (!willLog(channel, WTFLogLevelWarning))
+ return;
+
+ log(channel, format, arguments...);
+ }
+
+ template<typename... Arguments>
+ inline void notice(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const
+ {
+ if (!willLog(channel, WTFLogLevelNotice))
+ return;
+
+ log(channel, format, arguments...);
+ }
+
+ template<typename... Arguments>
+ inline void info(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const
+ {
+ if (!willLog(channel, WTFLogLevelInfo))
+ return;
+
+ log(channel, format, arguments...);
+ }
+
+ template<typename... Arguments>
+ inline void debug(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const
+ {
+ if (!willLog(channel, WTFLogLevelDebug))
+ return;
+
+ log(channel, format, arguments...);
+ }
+
+ inline bool willLog(WTFLogChannel& channel, WTFLogLevel level) const
+ {
+ return m_enabled && channel.level >= level && channel.state != WTFLogChannelOff;
+ }
+
+ bool enabled() const { return m_enabled; }
+ void setEnabled(const void* owner, bool enabled)
+ {
+ ASSERT(owner == m_owner);
+ if (owner == m_owner)
+ m_enabled = enabled;
+ }
+
+private:
+ Logger(const void* owner) { m_owner = owner; }
+
+ static inline void log(WTFLogChannel& channel, const char* format, ...)
+ {
+ va_list arguments;
+ va_start(arguments, format);
+
+#if COMPILER(CLANG)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+#endif
+
+#if RELEASE_LOG_DISABLED
+ WTFLog(&channel, format, arguments);
+#else
+ String string = String::format(format, arguments);
+ os_log(channel.osLogChannel, "%{public}s", string.utf8().data());
+#endif
+
+#if COMPILER(CLANG)
+#pragma clang diagnostic pop
+#endif
+
+ va_end(arguments);
+ }
+
+ const void* m_owner;
+ bool m_enabled { true };
+};
+
+} // namespace PAL
+
Modified: trunk/Tools/ChangeLog (221094 => 221095)
--- trunk/Tools/ChangeLog 2017-08-23 19:50:42 UTC (rev 221094)
+++ trunk/Tools/ChangeLog 2017-08-23 20:01:59 UTC (rev 221095)
@@ -1,3 +1,14 @@
+2017-08-23 Eric Carlson <[email protected]>
+
+ Platform code should be able to safely log in release builds
+ https://bugs.webkit.org/show_bug.cgi?id=175854
+ <rdar://problem/34022930>
+
+ Reviewed by Jer Noble.
+
+ * TestWebKitAPI/Tests/WebCore/Logging.cpp:
+ (TestWebKitAPI::TEST_F):
+
2017-08-23 Jonathan Bedard <[email protected]>
Access expectations path through apple_additions
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/Logging.cpp (221094 => 221095)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/Logging.cpp 2017-08-23 19:50:42 UTC (rev 221094)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/Logging.cpp 2017-08-23 20:01:59 UTC (rev 221095)
@@ -25,11 +25,13 @@
#include "config.h"
#include "WTFStringUtilities.h"
+#include <pal/Logger.h>
#include <wtf/Assertions.h>
#include <wtf/MainThread.h>
#define LOG_CHANNEL_PREFIX Test
+using namespace PAL;
using namespace WTF;
const char* logTestingSubsystem = "com.webkit.testing";
@@ -263,9 +265,34 @@
EXPECT_EQ(0u, output().length());
enabled = false;
- RELEASE_LOG_WITH_LEVEL_IF(enabled, Channel1, WTFLogLevelWarning, "or I shall taunt you a second time!");
+ RELEASE_LOG_WITH_LEVEL_IF(enabled, Channel1, WTFLogLevelWarning, "or I shall taunt you a second time! %i", 12);
EXPECT_EQ(0u, output().length());
}
+
+TEST_F(LoggingTest, Logger)
+{
+ Ref<Logger> logger = Logger::create(this);
+ EXPECT_TRUE(logger->enabled());
+
+ WTFSetLogChannelLevel(&TestChannel1, WTFLogLevelError);
+ logger->error(TestChannel1, "What, Ridden on a horse?");
+ EXPECT_TRUE(output().contains("horse?", false));
+
+ logger->warning(TestChannel1, "You're using coconuts!");
+ EXPECT_EQ(0u, output().length());
+ logger->notice(TestChannel1, "You're using coconuts!");
+ EXPECT_EQ(0u, output().length());
+ logger->info(TestChannel1, "You're using coconuts!");
+ EXPECT_EQ(0u, output().length());
+ logger->debug(TestChannel1, "You're using coconuts!");
+ EXPECT_EQ(0u, output().length());
+
+ logger->setEnabled(this, false);
+ EXPECT_FALSE(logger->enabled());
+ logger->error(TestChannel1, "You've got two empty halves of coconuts");
+ EXPECT_EQ(0u, output().length());
+}
+
#endif
} // namespace TestWebKitAPI