Changeset 221288 in webkit
- Timestamp:
- Aug 28, 2017 7:59:18 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/PAL/ChangeLog
r221276 r221288 1 2017-08-28 Eric Carlson <eric.carlson@apple.com> 2 3 Logger should use makeString instead of String::format 4 https://bugs.webkit.org/show_bug.cgi?id=176035 5 6 Reviewed by Jer Noble. 7 8 * pal/Logger.h: 9 (PAL::LogArgument::toString): 10 (PAL::Logger::logAlways): 11 (PAL::Logger::error): 12 (PAL::Logger::warning): 13 (PAL::Logger::notice): 14 (PAL::Logger::info): 15 (PAL::Logger::debug): 16 (PAL::Logger::MethodAndPointer::MethodAndPointer): 17 (PAL::Logger::log): 18 (PAL::LogArgument<Logger::MethodAndPointer>::toString): 19 1 20 2017-08-28 Andy Estes <aestes@apple.com> 2 21 -
trunk/Source/WebCore/PAL/pal/Logger.h
r221221 r221288 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 … … 27 27 28 28 #include <wtf/Assertions.h> 29 #include <wtf/HexNumber.h> 29 30 #include <wtf/Noncopyable.h> 30 31 #include <wtf/RefCounted.h> 31 32 #include <wtf/RefPtr.h> 33 #include <wtf/text/StringBuilder.h> 32 34 #include <wtf/text/WTFString.h> 33 35 34 36 namespace PAL { 37 38 template<typename T> 39 struct LogArgument { 40 template<typename U = T> static typename std::enable_if<std::is_same<U, int>::value, String>::type toString(int argument) { return String::number(argument); } 41 template<typename U = T> static typename std::enable_if<std::is_same<U, float>::value, String>::type toString(float argument) { return String::number(argument); } 42 template<typename U = T> static typename std::enable_if<std::is_same<U, double>::value, String>::type toString(double argument) { return String::number(argument); } 43 template<typename U = T> static typename std::enable_if<std::is_same<U, String>::value, String>::type toString(String argument) { return argument; } 44 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); } 45 template<size_t length> static String toString(const char (&argument)[length]) { return String(argument); } 46 }; 35 47 36 48 class Logger : public RefCounted<Logger> { … … 43 55 44 56 template<typename... Arguments> 45 inline void logAlways(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)57 inline void logAlways(WTFLogChannel& channel, const Arguments&... arguments) 46 58 { 47 59 #if RELEASE_LOG_DISABLED … … 49 61 // on some systems, so don't allow it. 50 62 UNUSED_PARAM(channel); 51 UNUSED_PARAM(format);52 63 #else 53 64 if (!willLog(channel, WTFLogLevelAlways)) 54 65 return; 55 66 56 log(channel, format,arguments...);67 log(channel, arguments...); 57 68 #endif 58 69 } 59 70 60 71 template<typename... Arguments> 61 inline void error(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)72 inline void error(WTFLogChannel& channel, const Arguments&... arguments) 62 73 { 63 74 if (!willLog(channel, WTFLogLevelError)) 64 75 return; 65 76 66 log(channel, format,arguments...);77 log(channel, arguments...); 67 78 } 68 79 69 80 template<typename... Arguments> 70 inline void warning(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)81 inline void warning(WTFLogChannel& channel, const Arguments&... arguments) 71 82 { 72 83 if (!willLog(channel, WTFLogLevelWarning)) 73 84 return; 74 85 75 log(channel, format,arguments...);86 log(channel, arguments...); 76 87 } 77 88 78 89 template<typename... Arguments> 79 inline void notice(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)90 inline void notice(WTFLogChannel& channel, const Arguments&... arguments) 80 91 { 81 92 if (!willLog(channel, WTFLogLevelNotice)) 82 93 return; 83 94 84 log(channel, format,arguments...);95 log(channel, arguments...); 85 96 } 86 97 87 98 template<typename... Arguments> 88 inline void info(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)99 inline void info(WTFLogChannel& channel, const Arguments&... arguments) 89 100 { 90 101 if (!willLog(channel, WTFLogLevelInfo)) 91 102 return; 92 103 93 log(channel, format,arguments...);104 log(channel, arguments...); 94 105 } 95 106 96 107 template<typename... Arguments> 97 inline void debug(WTFLogChannel& channel, const char* format, const Arguments&... arguments) const WTF_ATTRIBUTE_PRINTF(3, 0)108 inline void debug(WTFLogChannel& channel, const Arguments&... arguments) 98 109 { 99 110 if (!willLog(channel, WTFLogLevelDebug)) 100 111 return; 101 112 102 log(channel, format,arguments...);113 log(channel, arguments...); 103 114 } 104 115 … … 122 133 } 123 134 135 struct MethodAndPointer { 136 MethodAndPointer(const char* methodName, void* objectPtr) 137 : methodName(methodName) 138 , objectPtr(reinterpret_cast<uintptr_t>(objectPtr)) 139 { 140 } 141 142 const char* methodName; 143 uintptr_t objectPtr; 144 }; 145 124 146 private: 125 147 Logger(const void* owner) { m_owner = owner; } 126 148 127 static inline void log(WTFLogChannel& channel, const char* format, ...) 149 template<typename... Argument> 150 static inline void log(WTFLogChannel& channel, const Argument&... arguments) 128 151 { 129 va_list arguments; 130 va_start(arguments, format); 131 132 #if COMPILER(GCC_OR_CLANG) 133 #pragma GCC diagnostic push 134 #pragma GCC diagnostic ignored "-Wformat-nonliteral" 135 #endif 136 String string = String::formatWithArguments(format, arguments); 137 #if COMPILER(GCC_OR_CLANG) 138 #pragma GCC diagnostic pop 139 #endif 152 String string = makeString(LogArgument<Argument>::toString(arguments)...); 140 153 141 154 #if RELEASE_LOG_DISABLED … … 144 157 os_log(channel.osLogChannel, "%{public}s", string.utf8().data()); 145 158 #endif 146 147 va_end(arguments);148 159 } 149 160 … … 152 163 }; 153 164 165 template <> 166 struct LogArgument<Logger::MethodAndPointer> { 167 static String toString(const Logger::MethodAndPointer& value) 168 { 169 StringBuilder builder; 170 builder.append(value.methodName); 171 builder.appendLiteral("(0x"); 172 appendUnsigned64AsHex(value.objectPtr, builder); 173 builder.appendLiteral(") "); 174 return builder.toString(); 175 } 176 }; 177 154 178 } // namespace PAL 155 179 -
trunk/Tools/ChangeLog
r221284 r221288 1 2017-08-28 Eric Carlson <eric.carlson@apple.com> 2 3 Logger should use makeString instead of String::format 4 https://bugs.webkit.org/show_bug.cgi?id=176035 5 6 Reviewed by Jer Noble. 7 8 * TestWebKitAPI/Tests/WebCore/Logging.cpp: 9 (TestWebKitAPI::TEST_F): Update test. 10 1 11 2017-08-28 Michael Catanzaro <mcatanzaro@igalia.com> 2 12 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/Logging.cpp
r221221 r221288 268 268 269 269 WTFSetLogChannelLevel(&TestChannel1, WTFLogLevelError); 270 logger->error(TestChannel1, "%s %s", "What,", "ridden on a horse?"); 270 logger->error(TestChannel1, "You're using coconuts!"); 271 EXPECT_TRUE(output().contains("You're using coconuts!", false)); 272 logger->warning(TestChannel1, "You're using coconuts!"); 273 EXPECT_EQ(0u, output().length()); 274 logger->notice(TestChannel1, "You're using coconuts!"); 275 EXPECT_EQ(0u, output().length()); 276 logger->info(TestChannel1, "You're using coconuts!"); 277 EXPECT_EQ(0u, output().length()); 278 logger->debug(TestChannel1, "You're using coconuts!"); 279 EXPECT_EQ(0u, output().length()); 280 281 logger->error(TestChannel1, Logger::MethodAndPointer("LoggingTest::Logger", this) , ": test output"); 282 EXPECT_TRUE(output().contains("LoggingTest::Logger(", false)); 283 284 logger->error(TestChannel1, "What is ", 1, " + " , 12.5F, "?"); 285 EXPECT_TRUE(output().contains("What is 1 + 12.5?", false)); 286 287 logger->error(TestChannel1, "What, ", "ridden on a horse?"); 271 288 EXPECT_TRUE(output().contains("What, ridden on a horse?", false)); 272 273 logger->warning(TestChannel1, "You're using coconuts!");274 EXPECT_EQ(0u, output().length());275 logger->notice(TestChannel1, "You're using coconuts!");276 EXPECT_EQ(0u, output().length());277 logger->info(TestChannel1, "You're using coconuts!");278 EXPECT_EQ(0u, output().length());279 logger->debug(TestChannel1, "You're using coconuts!");280 EXPECT_EQ(0u, output().length());281 289 282 290 logger->setEnabled(this, false); … … 287 295 logger->setEnabled(this, true); 288 296 EXPECT_TRUE(logger->enabled()); 289 logger->error(TestChannel1, " %s %s", "You've got two empty halves of", "coconuts!");290 EXPECT_TRUE(output().contains("You've got twoempty halves of coconuts!", false));297 logger->error(TestChannel1, "You've got ", 2, " empty halves of ", "coconuts!"); 298 EXPECT_TRUE(output().contains("You've got 2 empty halves of coconuts!", false)); 291 299 292 300 WTFSetLogChannelLevel(&TestChannel1, WTFLogLevelError); 293 logger->logAlways(TestChannel1, " %s", "I shall taunt you a second time!");301 logger->logAlways(TestChannel1, "I shall taunt you a second time!"); 294 302 EXPECT_TRUE(output().contains("I shall taunt you a second time!", false)); 295 303
Note: See TracChangeset
for help on using the changeset viewer.