Modified: trunk/Source/WebCore/PAL/pal/Logger.h (221287 => 221288)
--- trunk/Source/WebCore/PAL/pal/Logger.h 2017-08-29 02:18:29 UTC (rev 221287)
+++ trunk/Source/WebCore/PAL/pal/Logger.h 2017-08-29 02:59:18 UTC (rev 221288)
@@ -20,19 +20,31 @@
* 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.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <wtf/Assertions.h>
+#include <wtf/HexNumber.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
+#include <wtf/text/StringBuilder.h>
#include <wtf/text/WTFString.h>
namespace PAL {
+template<typename T>
+struct LogArgument {
+ template<typename U = T> static typename std::enable_if<std::is_same<U, int>::value, String>::type toString(int argument) { return String::number(argument); }
+ template<typename U = T> static typename std::enable_if<std::is_same<U, float>::value, String>::type toString(float argument) { return String::number(argument); }
+ template<typename U = T> static typename std::enable_if<std::is_same<U, double>::value, String>::type toString(double argument) { return String::number(argument); }
+ template<typename U = T> static typename std::enable_if<std::is_same<U, String>::value, String>::type toString(String argument) { return argument; }
+ template<typename U = T> static typename std::enable_if<std::is_same<U, const char*>::value, String>::type toString(const char* argument) { return String(argument); }
+ template<size_t length> static String toString(const char (&argument)[length]) { return String(argument); }
+};
+
class Logger : public RefCounted<Logger> {
WTF_MAKE_NONCOPYABLE(Logger);
public:
@@ -42,64 +54,63 @@
}
template<typename... Arguments>
- inline void logAlways(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)
+ inline void logAlways(WTFLogChannel& channel, const Arguments&... arguments)
{
#if RELEASE_LOG_DISABLED
// "Standard" WebCore logging goes to stderr, which is captured in layout test output and can generally be a problem
// on some systems, so don't allow it.
UNUSED_PARAM(channel);
- UNUSED_PARAM(format);
#else
if (!willLog(channel, WTFLogLevelAlways))
return;
- log(channel, format, arguments...);
+ log(channel, arguments...);
#endif
}
template<typename... Arguments>
- inline void error(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)
+ inline void error(WTFLogChannel& channel, const Arguments&... arguments)
{
if (!willLog(channel, WTFLogLevelError))
return;
- log(channel, format, arguments...);
+ log(channel, arguments...);
}
template<typename... Arguments>
- inline void warning(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)
+ inline void warning(WTFLogChannel& channel, const Arguments&... arguments)
{
if (!willLog(channel, WTFLogLevelWarning))
return;
- log(channel, format, arguments...);
+ log(channel, arguments...);
}
template<typename... Arguments>
- inline void notice(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)
+ inline void notice(WTFLogChannel& channel, const Arguments&... arguments)
{
if (!willLog(channel, WTFLogLevelNotice))
return;
- log(channel, format, arguments...);
+ log(channel, arguments...);
}
template<typename... Arguments>
- inline void info(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)
+ inline void info(WTFLogChannel& channel, const Arguments&... arguments)
{
if (!willLog(channel, WTFLogLevelInfo))
return;
- log(channel, format, arguments...);
+ log(channel, arguments...);
}
template<typename... Arguments>
- inline void debug(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)
+ inline void debug(WTFLogChannel& channel, const Arguments&... arguments)
{
if (!willLog(channel, WTFLogLevelDebug))
return;
- log(channel, format, arguments...);
+ log(channel, arguments...);
}
inline bool willLog(WTFLogChannel& channel, WTFLogLevel level) const
@@ -121,30 +132,30 @@
m_enabled = enabled;
}
+ struct MethodAndPointer {
+ MethodAndPointer(const char* methodName, void* objectPtr)
+ : methodName(methodName)
+ , objectPtr(reinterpret_cast<uintptr_t>(objectPtr))
+ {
+ }
+
+ const char* methodName;
+ uintptr_t objectPtr;
+ };
+
private:
Logger(const void* owner) { m_owner = owner; }
- static inline void log(WTFLogChannel& channel, const char* format, ...)
+ template<typename... Argument>
+ static inline void log(WTFLogChannel& channel, const Argument&... arguments)
{
- va_list arguments;
- va_start(arguments, format);
+ String string = makeString(LogArgument<Argument>::toString(arguments)...);
-#if COMPILER(GCC_OR_CLANG)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
-#endif
- String string = String::formatWithArguments(format, arguments);
-#if COMPILER(GCC_OR_CLANG)
-#pragma GCC diagnostic pop
-#endif
-
#if RELEASE_LOG_DISABLED
WTFLog(&channel, "%s", string.utf8().data());
#else
os_log(channel.osLogChannel, "%{public}s", string.utf8().data());
#endif
-
- va_end(arguments);
}
const void* m_owner;
@@ -151,5 +162,18 @@
bool m_enabled { true };
};
+template <>
+struct LogArgument<Logger::MethodAndPointer> {
+ static String toString(const Logger::MethodAndPointer& value)
+ {
+ StringBuilder builder;
+ builder.append(value.methodName);
+ builder.appendLiteral("(0x");
+ appendUnsigned64AsHex(value.objectPtr, builder);
+ builder.appendLiteral(") ");
+ return builder.toString();
+ }
+};
+
} // namespace PAL
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/Logging.cpp (221287 => 221288)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/Logging.cpp 2017-08-29 02:18:29 UTC (rev 221287)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/Logging.cpp 2017-08-29 02:59:18 UTC (rev 221288)
@@ -267,9 +267,8 @@
EXPECT_TRUE(logger->enabled());
WTFSetLogChannelLevel(&TestChannel1, WTFLogLevelError);
- logger->error(TestChannel1, "%s %s", "What,", "ridden on a horse?");
- EXPECT_TRUE(output().contains("What, ridden on a horse?", false));
-
+ logger->error(TestChannel1, "You're using coconuts!");
+ EXPECT_TRUE(output().contains("You're using coconuts!", false));
logger->warning(TestChannel1, "You're using coconuts!");
EXPECT_EQ(0u, output().length());
logger->notice(TestChannel1, "You're using coconuts!");
@@ -279,6 +278,15 @@
logger->debug(TestChannel1, "You're using coconuts!");
EXPECT_EQ(0u, output().length());
+ logger->error(TestChannel1, Logger::MethodAndPointer("LoggingTest::Logger", this) , ": test output");
+ EXPECT_TRUE(output().contains("LoggingTest::Logger(", false));
+
+ logger->error(TestChannel1, "What is ", 1, " + " , 12.5F, "?");
+ EXPECT_TRUE(output().contains("What is 1 + 12.5?", false));
+
+ logger->error(TestChannel1, "What, ", "ridden on a horse?");
+ EXPECT_TRUE(output().contains("What, ridden on a horse?", false));
+
logger->setEnabled(this, false);
EXPECT_FALSE(logger->enabled());
logger->error(TestChannel1, "You've got two empty halves of coconuts");
@@ -286,11 +294,11 @@
logger->setEnabled(this, true);
EXPECT_TRUE(logger->enabled());
- logger->error(TestChannel1, "%s %s", "You've got two empty halves of", "coconuts!");
- EXPECT_TRUE(output().contains("You've got two empty halves of coconuts!", false));
+ logger->error(TestChannel1, "You've got ", 2, " empty halves of ", "coconuts!");
+ EXPECT_TRUE(output().contains("You've got 2 empty halves of coconuts!", false));
WTFSetLogChannelLevel(&TestChannel1, WTFLogLevelError);
- logger->logAlways(TestChannel1, "%s", "I shall taunt you a second time!");
+ logger->logAlways(TestChannel1, "I shall taunt you a second time!");
EXPECT_TRUE(output().contains("I shall taunt you a second time!", false));
logger->setEnabled(this, false);