Title: [221494] trunk
Revision
221494
Author
eric.carl...@apple.com
Date
2017-09-01 13:40:11 -0700 (Fri, 01 Sep 2017)

Log Message

Switch HTMLMediaElement to release logging
https://bugs.webkit.org/show_bug.cgi?id=176065

Reviewed by Jer Noble.

Source/WebCore:

* dom/Document.cpp:
(WebCore::Document::privateBrowsingStateDidChange): Disable the logger when private browsing
mode is enabled.
(WebCore::Document::logger const):
* dom/Document.h:

Convert debug-only logging to configurable release logging.
* html/HTMLMediaElement.cpp:
(PAL::LogArgument<WebCore::URL>::toString): Logger template for URL that returns the url as a
String when only when the LOG_DISABLED build flag is not defined. Returns "[url]" when it is.
* html/HTMLMediaElement.h:

Source/WTF:

* wtf/MediaTime.cpp:
(WTF::MediaTime::dump const): Use toString.
(WTF::MediaTime::toString const): New.
* wtf/MediaTime.h:
(PAL::LogArgument<WTF::MediaTime>::toString): Logger template.

Tools:

* TestWebKitAPI/Tests/WebCore/Logging.cpp:
(TestWebKitAPI::LogObserver::level const):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (221493 => 221494)


--- trunk/Source/WTF/ChangeLog	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Source/WTF/ChangeLog	2017-09-01 20:40:11 UTC (rev 221494)
@@ -1,3 +1,16 @@
+2017-09-01  Eric Carlson  <eric.carl...@apple.com>
+
+        Switch HTMLMediaElement to release logging
+        https://bugs.webkit.org/show_bug.cgi?id=176065
+
+        Reviewed by Jer Noble.
+
+        * wtf/MediaTime.cpp:
+        (WTF::MediaTime::dump const): Use toString.
+        (WTF::MediaTime::toString const): New.
+        * wtf/MediaTime.h:
+        (PAL::LogArgument<WTF::MediaTime>::toString): Logger template.
+
 2017-08-31  Don Olmstead  <don.olmst...@sony.com>
 
         [CMake] Make USE_CF conditional within Windows

Modified: trunk/Source/WTF/wtf/MediaTime.cpp (221493 => 221494)


--- trunk/Source/WTF/wtf/MediaTime.cpp	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Source/WTF/wtf/MediaTime.cpp	2017-09-01 20:40:11 UTC (rev 221494)
@@ -34,6 +34,7 @@
 #include <wtf/CheckedArithmetic.h>
 #include <wtf/MathExtras.h>
 #include <wtf/PrintStream.h>
+#include <wtf/text/StringBuilder.h>
 
 namespace WTF {
 
@@ -551,6 +552,22 @@
     out.print(toDouble(), "}");
 }
 
+String MediaTime::toString() const
+{
+    StringBuilder builder;
+
+    builder.append("{");
+    if (!hasDoubleValue()) {
+        builder.append(String::number(m_timeValue));
+        builder.append("/");
+        builder.append(String::number(m_timeScale));
+        builder.append(" = ");
+    }
+    builder.append(String::number(toDouble()));
+    builder.append("}");
+    return builder.toString();
+}
+
 MediaTime abs(const MediaTime& rhs)
 {
     if (rhs.isInvalid())

Modified: trunk/Source/WTF/wtf/MediaTime.h (221493 => 221494)


--- trunk/Source/WTF/wtf/MediaTime.h	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Source/WTF/wtf/MediaTime.h	2017-09-01 20:40:11 UTC (rev 221494)
@@ -30,6 +30,7 @@
 #define WTF_MediaTime_h
 
 #include <wtf/FastMalloc.h>
+#include <wtf/text/WTFString.h>
 
 #include <cmath>
 #include <limits>
@@ -108,6 +109,7 @@
     const uint32_t& timeScale() const { return m_timeScale; }
 
     void dump(PrintStream& out) const;
+    String toString() const;
 
     // Make the following casts errors:
     operator double() const = delete;
@@ -167,4 +169,18 @@
 using WTF::MediaTime;
 using WTF::abs;
 
+namespace PAL {
+
+template<typename Type>
+struct LogArgument;
+
+template <>
+struct LogArgument<WTF::MediaTime> {
+    static String toString(const WTF::MediaTime& time)
+    {
+        return time.toString();
+    }
+};
+}
+
 #endif

Modified: trunk/Source/WebCore/ChangeLog (221493 => 221494)


--- trunk/Source/WebCore/ChangeLog	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Source/WebCore/ChangeLog	2017-09-01 20:40:11 UTC (rev 221494)
@@ -1,3 +1,22 @@
+2017-09-01  Eric Carlson  <eric.carl...@apple.com>
+
+        Switch HTMLMediaElement to release logging
+        https://bugs.webkit.org/show_bug.cgi?id=176065
+
+        Reviewed by Jer Noble.
+
+        * dom/Document.cpp:
+        (WebCore::Document::privateBrowsingStateDidChange): Disable the logger when private browsing
+        mode is enabled.
+        (WebCore::Document::logger const):
+        * dom/Document.h:
+
+        Convert debug-only logging to configurable release logging.
+        * html/HTMLMediaElement.cpp:
+        (PAL::LogArgument<WebCore::URL>::toString): Logger template for URL that returns the url as a
+        String when only when the LOG_DISABLED build flag is not defined. Returns "[url]" when it is.
+        * html/HTMLMediaElement.h:
+
 2017-09-01  Simon Fraser  <simon.fra...@apple.com>
 
         transformCanLikelyUseFastPath() can read off the end of a string

Modified: trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj (221493 => 221494)


--- trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj	2017-09-01 20:40:11 UTC (rev 221494)
@@ -22,6 +22,7 @@
 
 /* Begin PBXBuildFile section */
 		0708AC331F4C874B001F788F /* Logger.h in Headers */ = {isa = PBXBuildFile; fileRef = 0708AC321F4C874A001F788F /* Logger.h */; };
+		07377ADC1F5777D90027F16D /* LoggerHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 07377ADB1F5777D70027F16D /* LoggerHelper.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 */; };
@@ -136,6 +137,7 @@
 
 /* Begin PBXFileReference section */
 		0708AC321F4C874A001F788F /* Logger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Logger.h; sourceTree = "<group>"; };
+		07377ADB1F5777D70027F16D /* LoggerHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoggerHelper.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; path = CFLocaleSPI.h; sourceTree = "<group>"; };
 		0C2DA0681F33CA8400DBC317 /* CFNetworkConnectionCacheSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFNetworkConnectionCacheSPI.h; sourceTree = "<group>"; };
@@ -408,6 +410,7 @@
 				A30D411D1F0DD0AC00B71954 /* text */,
 				0C2D9E721EEF5AF600DBC317 /* ExportMacros.h */,
 				0708AC321F4C874A001F788F /* Logger.h */,
+				07377ADB1F5777D70027F16D /* LoggerHelper.h */,
 				A3C66CDA1F462D6A009E6EE9 /* SessionID.cpp */,
 				A3C66CDB1F462D6A009E6EE9 /* SessionID.h */,
 			);
@@ -532,6 +535,7 @@
 				0C2DA1431F3BEB4900DBC317 /* IOPSLibSPI.h in Headers */,
 				0C2DA1441F3BEB4900DBC317 /* IOReturnSPI.h in Headers */,
 				0C2DA1451F3BEB4900DBC317 /* IOSurfaceSPI.h in Headers */,
+				07377ADC1F5777D90027F16D /* LoggerHelper.h in Headers */,
 				0C2DA1461F3BEB4900DBC317 /* IOTypesSPI.h in Headers */,
 				A30D41211F0DD0EA00B71954 /* KillRing.h in Headers */,
 				0C5AF91C1F43A4C7002EAC02 /* LaunchServicesSPI.h in Headers */,

Modified: trunk/Source/WebCore/PAL/pal/Logger.h (221493 => 221494)


--- trunk/Source/WebCore/PAL/pal/Logger.h	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Source/WebCore/PAL/pal/Logger.h	2017-09-01 20:40:11 UTC (rev 221494)
@@ -54,7 +54,7 @@
     class Observer {
     public:
         virtual ~Observer() { }
-        virtual void didLogMessage(const WTFLogChannel&, const String&) = 0;
+        virtual void didLogMessage(const WTFLogChannel&, WTFLogLevel, const String&) = 0;
     };
 
     static Ref<Logger> create(const void* owner)
@@ -63,7 +63,7 @@
     }
 
     template<typename... Arguments>
-    inline void logAlways(WTFLogChannel& channel, const Arguments&... arguments) const
+    inline void logAlways(WTFLogChannel& channel, UNUSED_FUNCTION const Arguments&... arguments) const
     {
 #if RELEASE_LOG_DISABLED
         // "Standard" WebCore logging goes to stderr, which is captured in layout test output and can generally be a problem
@@ -73,7 +73,7 @@
         if (!willLog(channel, WTFLogLevelAlways))
             return;
 
-        log(channel, arguments...);
+        log(channel, WTFLogLevelAlways, arguments...);
 #endif
     }
 
@@ -83,7 +83,7 @@
         if (!willLog(channel, WTFLogLevelError))
             return;
 
-        log(channel, arguments...);
+        log(channel, WTFLogLevelError, arguments...);
     }
 
     template<typename... Arguments>
@@ -92,7 +92,7 @@
         if (!willLog(channel, WTFLogLevelWarning))
             return;
 
-        log(channel, arguments...);
+        log(channel, WTFLogLevelWarning, arguments...);
     }
 
     template<typename... Arguments>
@@ -101,7 +101,7 @@
         if (!willLog(channel, WTFLogLevelNotice))
             return;
 
-        log(channel, arguments...);
+        log(channel, WTFLogLevelNotice, arguments...);
     }
 
     template<typename... Arguments>
@@ -110,7 +110,7 @@
         if (!willLog(channel, WTFLogLevelInfo))
             return;
 
-        log(channel, arguments...);
+        log(channel, WTFLogLevelInfo, arguments...);
     }
 
     template<typename... Arguments>
@@ -119,7 +119,7 @@
         if (!willLog(channel, WTFLogLevelDebug))
             return;
 
-        log(channel, arguments...);
+        log(channel, WTFLogLevelDebug, arguments...);
     }
 
     inline bool willLog(const WTFLogChannel& channel, WTFLogLevel level) const
@@ -178,7 +178,7 @@
     }
 
     template<typename... Argument>
-    static inline void log(WTFLogChannel& channel, const Argument&... arguments)
+    static inline void log(WTFLogChannel& channel, WTFLogLevel level, const Argument&... arguments)
     {
         String logMessage = makeString(LogArgument<Argument>::toString(arguments)...);
 
@@ -189,7 +189,7 @@
 #endif
 
         for (Observer& observer : observers())
-            observer.didLogMessage(channel, logMessage);
+            observer.didLogMessage(channel, level, logMessage);
     }
 
     static Vector<std::reference_wrapper<Observer>>& observers()
@@ -202,25 +202,6 @@
     bool m_enabled { true };
 };
 
-class LogHelper {
-public:
-    virtual ~LogHelper() = default;
-
-    virtual const Logger& logger() const = 0;
-    virtual const char* className() const = 0;
-    virtual WTFLogChannel& logChannel() const = 0;
-
-    inline bool willLog(WTFLogLevel level) const { return logger().willLog(logChannel(), level); }
-
-#define ALWAYS_LOG(...)     logger().logAlways(logChannel(), Logger::MethodAndPointer(className(), __func__, this), ##__VA_ARGS__)
-#define ERROR_LOG(...)      logger().error(logChannel(), Logger::MethodAndPointer(className(), __func__, this), ##__VA_ARGS__)
-#define WARNING_LOG(...)    logger().warning(logChannel(), Logger::MethodAndPointer(className(), __func__, this), ##__VA_ARGS__)
-#define NOTICE_LOG(...)     logger().notice(logChannel(), Logger::MethodAndPointer(className(), __func__, this), ##__VA_ARGS__)
-#define INFO_LOG(...)       logger().info(logChannel(), Logger::MethodAndPointer(className(), __func__, this), ##__VA_ARGS__)
-#define DEBUG_LOG(...)      logger().debug(logChannel(), Logger::MethodAndPointer(className(), __func__, this), ##__VA_ARGS__)
-
-};
-
 template <>
 struct LogArgument<Logger::MethodAndPointer> {
     static String toString(const Logger::MethodAndPointer& value)

Added: trunk/Source/WebCore/PAL/pal/LoggerHelper.h (0 => 221494)


--- trunk/Source/WebCore/PAL/pal/LoggerHelper.h	                        (rev 0)
+++ trunk/Source/WebCore/PAL/pal/LoggerHelper.h	2017-09-01 20:40:11 UTC (rev 221494)
@@ -0,0 +1,66 @@
+/*
+ * 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
+
+namespace PAL {
+
+class LoggerHelper {
+public:
+    virtual ~LoggerHelper() = default;
+
+    virtual const Logger& logger() const = 0;
+    virtual const char* className() const = 0;
+    virtual WTFLogChannel& logChannel() const = 0;
+
+
+#if !RELEASE_LOG_DISABLED
+
+#define THIS Logger::MethodAndPointer(className(), __func__, this)
+
+#define ALWAYS_LOG(...)     logger().logAlways(logChannel(), __VA_ARGS__)
+#define ERROR_LOG(...)      logger().error(logChannel(), __VA_ARGS__)
+#define WARNING_LOG(...)    logger().warning(logChannel(), __VA_ARGS__)
+#define NOTICE_LOG(...)     logger().notice(logChannel(), __VA_ARGS__)
+#define INFO_LOG(...)       logger().info(logChannel(), __VA_ARGS__)
+#define DEBUG_LOG(...)      logger().debug(logChannel(), __VA_ARGS__)
+
+#else
+
+#define THIS ((void)0)
+
+#define ALWAYS_LOG(...)     ((void)0)
+#define ERROR_LOG(...)      ((void)0)
+#define ERROR_LOG(...)      ((void)0)
+#define WARNING_LOG(...)    ((void)0)
+#define NOTICE_LOG(...)     ((void)0)
+#define INFO_LOG(...)       ((void)0)
+#define DEBUG_LOG(...)      ((void)0)
+
+#endif
+    
+};
+
+} // namespace PAL

Modified: trunk/Source/WebCore/dom/Document.cpp (221493 => 221494)


--- trunk/Source/WebCore/dom/Document.cpp	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Source/WebCore/dom/Document.cpp	2017-09-01 20:40:11 UTC (rev 221494)
@@ -204,6 +204,7 @@
 #include <ctime>
 #include <inspector/ConsoleMessage.h>
 #include <inspector/ScriptCallStack.h>
+#include <pal/Logger.h>
 #include <wtf/CurrentTime.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/SetForScope.h>
@@ -287,7 +288,7 @@
 #include "WebGPURenderingContext.h"
 #endif
 
-
+using namespace PAL;
 using namespace WTF;
 using namespace Unicode;
 
@@ -4863,6 +4864,10 @@
 
 void Document::privateBrowsingStateDidChange() 
 {
+    m_sessionID = SessionID::emptySessionID();
+    if (m_logger)
+        m_logger->setEnabled(this, sessionID().isAlwaysOnLoggingAllowed());
+
     for (auto* element : m_privateBrowsingStateChangedElements)
         element->privateBrowsingStateDidChange();
 }
@@ -7231,4 +7236,14 @@
         bodyElement->setAttributeWithoutSynchronization(vlinkAttr, value);
 }
 
+Logger& Document::logger() const
+{
+    if (!m_logger) {
+        m_logger = Logger::create(this);
+        m_logger->setEnabled(this, sessionID().isAlwaysOnLoggingAllowed());
+    }
+
+    return *m_logger;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/Document.h (221493 => 221494)


--- trunk/Source/WebCore/dom/Document.h	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Source/WebCore/dom/Document.h	2017-09-01 20:40:11 UTC (rev 221494)
@@ -75,6 +75,10 @@
 class InputCursor;
 }
 
+namespace PAL {
+class Logger;
+}
+
 namespace WebCore {
 
 class AXObjectCache;
@@ -1355,6 +1359,8 @@
     TextAutoSizing& textAutoSizing();
 #endif
 
+    PAL::Logger& logger() const;
+
 protected:
     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     Document(Frame*, const URL&, unsigned = DefaultDocumentClass, unsigned constructionFlags = 0);
@@ -1805,6 +1811,7 @@
 
     OrientationNotifier m_orientationNotifier;
     mutable PAL::SessionID m_sessionID;
+    mutable RefPtr<PAL::Logger> m_logger;
 
     static bool hasEverCreatedAnAXObjectCache;
 };

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (221493 => 221494)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-09-01 20:40:11 UTC (rev 221494)
@@ -88,6 +88,7 @@
 #include "UserContentController.h"
 #include "UserGestureIndicator.h"
 #include <limits>
+#include <pal/Logger.h>
 #include <pal/SessionID.h>
 #include <pal/system/SleepDisabler.h>
 #include <runtime/Uint8Array.h>
@@ -164,8 +165,27 @@
 #include "VideoFullscreenModel.h"
 #endif
 
-#define RELEASE_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(document().page() && document().page()->isAlwaysOnLoggingAllowed(), Media, "%p - HTMLMediaElement::" fmt, this, ##__VA_ARGS__)
+namespace PAL {
+template <>
+struct LogArgument<WebCore::URL> {
+    static String toString(const WebCore::URL& url)
+    {
+#if !LOG_DISABLED
+        static const unsigned maximumURLLengthForLogging = 512;
 
+        if (url.string().length() < maximumURLLengthForLogging)
+            return url.string();
+        return url.string().substring(0, maximumURLLengthForLogging) + "...";
+#else
+        UNUSED_PARAM(url);
+        return "[url]";
+#endif
+    }
+};
+}
+
+using namespace PAL;
+
 namespace WebCore {
 
 static const Seconds SeekRepeatDelay { 100_ms };
@@ -186,21 +206,7 @@
     value &= ~flags;
 }
 
-#if !LOG_DISABLED
-static String urlForLoggingMedia(const URL& url)
-{
-    static const unsigned maximumURLLengthForLogging = 128;
-
-    if (url.string().length() < maximumURLLengthForLogging)
-        return url.string();
-    return url.string().substring(0, maximumURLLengthForLogging) + "...";
-}
-
-static const char* boolString(bool val)
-{
-    return val ? "true" : "false";
-}
-
+#if !RELEASE_LOG_DISABLED
 static String actionName(HTMLMediaElementEnums::DelayedActionType action)
 {
     StringBuilder actionBuilder;
@@ -212,6 +218,7 @@
         actionBuilder.append(#_actionType); \
     } \
 
+    ACTION(LoadMediaResource);
     ACTION(ConfigureTextTracks);
     ACTION(TextTrackChangesNotification);
     ACTION(ConfigureTextTrackDisplay);
@@ -218,20 +225,16 @@
     ACTION(CheckPlaybackTargetCompatablity);
     ACTION(CheckMediaState);
     ACTION(MediaEngineUpdated);
+    ACTION(UpdatePlayState);
 
-    return actionBuilder.toString();
+#undef ACTION
 
-#undef ACTION
+    String name = actionBuilder.toString();
+    ASSERT(!name.isEmpty());
+    return name;
 }
-
 #endif
 
-#ifndef LOG_MEDIA_EVENTS
-// Default to not logging events because so many are generated they can overwhelm the rest of
-// the logging.
-#define LOG_MEDIA_EVENTS 0
-#endif
-
 #ifndef LOG_CACHED_TIME_WARNINGS
 // Default to not logging warnings about excessive drift in the cached media time because it adds a
 // fair amount of overhead and logging.
@@ -447,10 +450,14 @@
     , m_processingPreferenceChange(false)
 #endif
     , m_mediaSession(std::make_unique<MediaElementSession>(*this))
+#if !RELEASE_LOG_DISABLED
+    , m_logger(&document.logger())
+#endif
 {
     allMediaElements().add(this);
 
-    LOG(Media, "HTMLMediaElement::HTMLMediaElement(%p)", this);
+    ALWAYS_LOG(THIS);
+
     setHasCustomStyleResolveCallbacks();
 
     m_mediaSession->addBehaviorRestriction(MediaElementSession::RequireUserGestureForFullscreen);
@@ -526,7 +533,7 @@
 
 HTMLMediaElement::~HTMLMediaElement()
 {
-    LOG(Media, "HTMLMediaElement::~HTMLMediaElement(%p)", this);
+    ALWAYS_LOG(THIS);
 
     beginIgnoringTrackDisplayUpdateRequests();
     allMediaElements().remove(this);
@@ -858,7 +865,7 @@
 
 Node::InsertionNotificationRequest HTMLMediaElement::insertedInto(ContainerNode& insertionPoint)
 {
-    LOG(Media, "HTMLMediaElement::insertedInto(%p)", this);
+    NOTICE_LOG(THIS);
 
     HTMLElement::insertedInto(insertionPoint);
     if (insertionPoint.isConnected()) {
@@ -917,7 +924,7 @@
 
 void HTMLMediaElement::removedFrom(ContainerNode& insertionPoint)
 {
-    LOG(Media, "HTMLMediaElement::removedFrom(%p)", this);
+    NOTICE_LOG(THIS);
 
     m_inActiveDocument = false;
     if (insertionPoint.isConnected()) {
@@ -967,7 +974,8 @@
 
 void HTMLMediaElement::scheduleDelayedAction(DelayedActionType actionType)
 {
-    LOG(Media, "HTMLMediaElement::scheduleDelayedAction(%p) - setting %s flag", this, actionName(actionType).utf8().data());
+    if (actionType ^ m_pendingActionFlags)
+        ALWAYS_LOG(THIS, "setting ", actionName(actionType), " flag");
 
 #if ENABLE(VIDEO_TRACK)
     if (actionType & ConfigureTextTracks)
@@ -1007,9 +1015,6 @@
 
 void HTMLMediaElement::scheduleEvent(const AtomicString& eventName)
 {
-#if LOG_MEDIA_EVENTS
-    LOG(Media, "HTMLMediaElement::scheduleEvent(%p) - scheduling '%s'", this, eventName.string().ascii().data());
-#endif
     RefPtr<Event> event = Event::create(eventName, false, true);
 
     // Don't set the event target, the event queue will set it in GenericEventQueue::timerFired and setting it here
@@ -1066,6 +1071,11 @@
     PendingActionFlags pendingActions = m_pendingActionFlags;
     m_pendingActionFlags = 0;
 
+    if (!pendingActions)
+        return;
+
+    ALWAYS_LOG(THIS, "setting ", actionName(static_cast<DelayedActionType>(pendingActions)), " flag");
+
 #if ENABLE(VIDEO_TRACK)
     if (pendingActions & ConfigureTextTracks)
         configureTextTracks();
@@ -1073,7 +1083,7 @@
 
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
     if (pendingActions & CheckPlaybackTargetCompatablity && m_isPlayingToWirelessTarget && !m_player->canPlayToWirelessPlaybackTarget()) {
-        LOG(Media, "HTMLMediaElement::pendingActionTimerFired(%p) - calling setShouldPlayToPlaybackTarget(false)", this);
+        NOTICE_LOG(THIS, "calling setShouldPlayToPlaybackTarget(false)");
         m_failedToPlayToWirelessTarget = true;
         m_player->setShouldPlayToPlaybackTarget(false);
     }
@@ -1150,7 +1160,7 @@
             break;
     }
 
-    LOG(Media, "HTMLMediaElement::canPlayType(%p) - [%s] -> %s", this, mimeType.utf8().data(), canPlay.utf8().data());
+    DEBUG_LOG(THIS, "[", mimeType, "] -> ", canPlay);
 
     return canPlay;
 }
@@ -1166,7 +1176,7 @@
 {
     Ref<HTMLMediaElement> protectedThis(*this); // prepareForLoad may result in a 'beforeload' event, which can make arbitrary DOM mutations.
 
-    LOG(Media, "HTMLMediaElement::load(%p)", this);
+    NOTICE_LOG(THIS);
 
     if (!m_mediaSession->dataLoadingPermitted(*this))
         return;
@@ -1185,7 +1195,7 @@
     // The Media Element Load Algorithm
     // 12 February 2017
 
-    LOG(Media, "HTMLMediaElement::prepareForLoad(%p)", this);
+    NOTICE_LOG(THIS);
 
     // 1 - Abort any already-running instance of the resource selection algorithm for this element.
     // Perform the cleanup required for the resource load algorithm to run.
@@ -1304,7 +1314,7 @@
         return;
 
     if (!m_mediaSession->pageAllowsDataLoading(*this)) {
-        LOG(Media, "HTMLMediaElement::selectMediaResource(%p) - not allowed to load in background, waiting", this);
+        ALWAYS_LOG(THIS, "not allowed to load in background, waiting");
         setShouldDelayLoadEvent(false);
         if (m_isWaitingUntilMediaCanStart)
             return;
@@ -1349,7 +1359,7 @@
             mode = Attribute;
             ASSERT(m_player);
             if (!m_player) {
-                RELEASE_LOG_ERROR(Media, "HTMLMediaElement::selectMediaResource(%p) - has srcAttr but m_player is not created", this);
+                ERROR_LOG(THIS, " - has srcAttr but m_player is not created");
                 return;
             }
         } else if (auto firstSource = childrenOfType<HTMLSourceElement>(*this).first()) {
@@ -1366,7 +1376,7 @@
             setShouldDelayLoadEvent(false);
             m_networkState = NETWORK_EMPTY;
 
-            LOG(Media, "HTMLMediaElement::selectMediaResource(%p) - nothing to load", this);
+            ALWAYS_LOG(THIS, "nothing to load");
             return;
         }
 
@@ -1396,7 +1406,7 @@
 
             ContentType contentType;
             loadResource(URL(), contentType, String());
-            LOG(Media, "HTMLMediaElement::selectMediaResource(%p) - using 'srcObject' property", this);
+            ALWAYS_LOG(THIS, "using 'srcObject' property");
 
             //    If that algorithm returns without aborting this one, then the load failed.
             // 4. Failed with media provider: Reaching this step indicates that the media resource
@@ -1419,7 +1429,7 @@
             URL absoluteURL = getNonEmptyURLAttribute(srcAttr);
             if (absoluteURL.isEmpty()) {
                 mediaLoadingFailed(MediaPlayer::FormatError);
-                LOG(Media, "HTMLMediaElement::selectMediaResource(%p) -  empty 'src'", this);
+                ALWAYS_LOG(THIS, "empty 'src'");
                 return;
             }
 
@@ -1440,7 +1450,7 @@
             // will have to pick a media engine based on the file extension.
             ContentType contentType;
             loadResource(absoluteURL, contentType, String());
-            LOG(Media, "HTMLMediaElement::selectMediaResource(%p) - using 'src' attribute url", this);
+            ALWAYS_LOG(THIS, "using 'src' attribute url");
 
             // 6. Failed with attribute: Reaching this step indicates that the media resource failed to load
             //    or that the given URL could not be resolved. Queue a task to run the dedicated media source failure steps.
@@ -1476,7 +1486,7 @@
 {
     ASSERT(initialURL.isEmpty() || isSafeToLoadURL(initialURL, Complain));
 
-    LOG(Media, "HTMLMediaElement::loadResource(%p) - %s, %s, %s", this, urlForLoggingMedia(initialURL).utf8().data(), contentType.raw().utf8().data(), keySystem.utf8().data());
+    NOTICE_LOG(THIS, initialURL, contentType.raw(), keySystem);
 
     Frame* frame = document().frame();
     if (!frame) {
@@ -1530,10 +1540,10 @@
 
     if (resource) {
         url = ""
-        LOG(Media, "HTMLMediaElement::loadResource(%p) - will load from app cache -> %s", this, urlForLoggingMedia(url).utf8().data());
+        NOTICE_LOG(THIS, "will load ", url, " from app cache");
     }
 
-    LOG(Media, "HTMLMediaElement::loadResource(%p) - m_currentSrc -> %s", this, urlForLoggingMedia(m_currentSrc).utf8().data());
+    NOTICE_LOG(THIS, "m_currentSrc is ", m_currentSrc);
 
     startProgressEventTimer();
 
@@ -1641,7 +1651,7 @@
     if (ignoreTrackDisplayUpdateRequests())
         return;
 
-    LOG(Media, "HTMLMediaElement::updateActiveTextTrackCues(%p)", this);
+    DEBUG_LOG(THIS);
 
     // 1 - Let current cues be a list of cues, initialized to contain all the
     // cues of all the hidden, showing, or showing by default text tracks of the
@@ -2041,7 +2051,7 @@
 bool HTMLMediaElement::isSafeToLoadURL(const URL& url, InvalidURLAction actionIfInvalid)
 {
     if (!url.isValid()) {
-        LOG(Media, "HTMLMediaElement::isSafeToLoadURL(%p) - %s -> FALSE because url is invalid", this, urlForLoggingMedia(url).utf8().data());
+        ERROR_LOG(THIS, url, " is invalid");
         return false;
     }
 
@@ -2049,12 +2059,12 @@
     if (!frame || !document().securityOrigin().canDisplay(url)) {
         if (actionIfInvalid == Complain)
             FrameLoader::reportLocalLoadFailed(frame, url.stringCenterEllipsizedToLength());
-        LOG(Media, "HTMLMediaElement::isSafeToLoadURL(%p) - %s -> FALSE rejected by SecurityOrigin", this, urlForLoggingMedia(url).utf8().data());
+            ERROR_LOG(THIS, url , " was rejected by SecurityOrigin");
         return false;
     }
 
     if (!isAllowedToLoadMediaURL(*this, url, isInUserAgentShadowTree())) {
-        LOG(Media, "HTMLMediaElement::isSafeToLoadURL(%p) - %s -> rejected by Content Security Policy", this, urlForLoggingMedia(url).utf8().data());
+        ERROR_LOG(THIS, url, " was rejected by Content Security Policy");
         return false;
     }
 
@@ -2073,7 +2083,7 @@
 
 void HTMLMediaElement::waitForSourceChange()
 {
-    LOG(Media, "HTMLMediaElement::waitForSourceChange(%p)", this);
+    NOTICE_LOG(THIS);
 
     stopPeriodicTimers();
     m_loadState = WaitingForSource;
@@ -2090,7 +2100,7 @@
 
 void HTMLMediaElement::noneSupported()
 {
-    LOG(Media, "HTMLMediaElement::noneSupported(%p)", this);
+    NOTICE_LOG(THIS);
 
     stopPeriodicTimers();
     m_loadState = WaitingForSource;
@@ -2131,8 +2141,6 @@
 
 void HTMLMediaElement::mediaLoadingFailedFatally(MediaPlayer::NetworkState error)
 {
-    LOG(Media, "HTMLMediaElement::mediaLoadingFailedFatally(%p) - error = %d", this, static_cast<int>(error));
-
     // 1 - The user agent should cancel the fetching process.
     stopPeriodicTimers();
     m_loadState = WaitingForSource;
@@ -2172,7 +2180,7 @@
 
 void HTMLMediaElement::cancelPendingEventsAndCallbacks()
 {
-    LOG(Media, "HTMLMediaElement::cancelPendingEventsAndCallbacks(%p)", this);
+    NOTICE_LOG(THIS);
     m_asyncEventQueue.cancelAllEvents();
 
     for (auto& source : childrenOfType<HTMLSourceElement>(*this))
@@ -2237,7 +2245,7 @@
         if (m_currentSourceNode)
             m_currentSourceNode->scheduleErrorEvent();
         else
-            LOG(Media, "HTMLMediaElement::setNetworkState(%p) - error event not sent, <source> was removed", this);
+            NOTICE_LOG(THIS, "error event not sent, <source> was removed");
 
         // 9.Otherwise.10 - Asynchronously await a stable state. The synchronous section consists of all the remaining steps of this algorithm until the algorithm says the synchronous section has ended.
 
@@ -2245,10 +2253,10 @@
         forgetResourceSpecificTracks();
 
         if (havePotentialSourceChild()) {
-            LOG(Media, "HTMLMediaElement::setNetworkState(%p) - scheduling next <source>", this);
+            NOTICE_LOG(THIS, "scheduling next <source>");
             scheduleNextSourceChild();
         } else {
-            LOG(Media, "HTMLMediaElement::setNetworkState(%p) - no more <source> elements, waiting", this);
+            NOTICE_LOG(THIS, "no more <source> elements, waiting");
             waitForSourceChange();
         }
 
@@ -2266,6 +2274,8 @@
         mediaControls()->reportedError();
     }
 
+    ERROR_LOG(THIS, "error = ", static_cast<int>(error));
+
     logMediaLoadRequest(document().page(), String(), stringForNetworkState(error), false);
 
     m_mediaSession->clientCharacteristicsChanged();
@@ -2273,7 +2283,8 @@
 
 void HTMLMediaElement::setNetworkState(MediaPlayer::NetworkState state)
 {
-    LOG(Media, "HTMLMediaElement::setNetworkState(%p) - new state = %d, current state = %d", this, static_cast<int>(state), static_cast<int>(m_networkState));
+    if (static_cast<int>(state) != static_cast<int>(m_networkState))
+        ALWAYS_LOG(THIS, "new state = ", static_cast<int>(state), ", current state = ", static_cast<int>(m_networkState));
 
     if (state == MediaPlayer::Empty) {
         // Just update the cached state and leave, we can't do anything.
@@ -2344,7 +2355,7 @@
         && m_readyState == HAVE_ENOUGH_DATA)
         return mediaSession().playbackPermitted(*this);
 
-    RELEASE_LOG(Media, "HTMLMediaElement::canTransitionFromAutoplayToPlay - page consent required");
+    ALWAYS_LOG(THIS, "page consent required");
     return MediaPlaybackDenialReason::PageConsentRequired;
 }
 
@@ -2360,8 +2371,6 @@
 
 void HTMLMediaElement::setReadyState(MediaPlayer::ReadyState state)
 {
-    LOG(Media, "HTMLMediaElement::setReadyState(%p) - new state = %d, current state = %d,", this, static_cast<int>(state), static_cast<int>(m_readyState));
-
     // Set "wasPotentiallyPlaying" BEFORE updating m_readyState, potentiallyPlaying() uses it
     bool wasPotentiallyPlaying = potentiallyPlaying();
 
@@ -2381,6 +2390,8 @@
     bool tracksAreReady = true;
 #endif
 
+    ALWAYS_LOG(THIS, "new state = ", static_cast<int>(state), ", current state = ", static_cast<int>(m_readyState));
+
     if (tracksAreReady)
         m_readyState = newState;
     else {
@@ -2760,19 +2771,17 @@
 
 void HTMLMediaElement::rewind(double timeDelta)
 {
-    LOG(Media, "HTMLMediaElement::rewind(%p) - %f", this, timeDelta);
     setCurrentTime(std::max(currentMediaTime() - MediaTime::createWithDouble(timeDelta), minTimeSeekable()));
 }
 
 void HTMLMediaElement::returnToRealtime()
 {
-    LOG(Media, "HTMLMediaElement::returnToRealtime(%p)", this);
     setCurrentTime(maxTimeSeekable());
 }
 
 void HTMLMediaElement::addPlayedRange(const MediaTime& start, const MediaTime& end)
 {
-    LOG(Media, "HTMLMediaElement::addPlayedRange(%p) - [%s, %s]", this, toString(start).utf8().data(), toString(end).utf8().data());
+    DEBUG_LOG(THIS, "[", start, ", ", end, "]");
     if (!m_playedTimeRanges)
         m_playedTimeRanges = TimeRanges::create();
     m_playedTimeRanges->ranges().add(start, end);
@@ -2785,7 +2794,7 @@
 
 void HTMLMediaElement::prepareToPlay()
 {
-    LOG(Media, "HTMLMediaElement::prepareToPlay(%p)", this);
+    NOTICE_LOG(THIS);
     if (m_havePreparedToPlay)
         return;
     m_havePreparedToPlay = true;
@@ -2800,7 +2809,7 @@
 
 void HTMLMediaElement::fastSeek(const MediaTime& time)
 {
-    LOG(Media, "HTMLMediaElement::fastSeek(%p) - %s", this, toString(time).utf8().data());
+    NOTICE_LOG(THIS, time);
     // 4.7.10.9 Seeking
     // 9. If the approximate-for-speed flag is set, adjust the new playback position to a value that will
     // allow for playback to resume promptly. If new playback position before this step is before current
@@ -2816,13 +2825,13 @@
 
 void HTMLMediaElement::seek(const MediaTime& time)
 {
-    LOG(Media, "HTMLMediaElement::seek(%p) - %s", this, toString(time).utf8().data());
+    NOTICE_LOG(THIS, time);
     seekWithTolerance(time, MediaTime::zeroTime(), MediaTime::zeroTime(), true);
 }
 
 void HTMLMediaElement::seekInternal(const MediaTime& time)
 {
-    LOG(Media, "HTMLMediaElement::seekInternal(%p) - %s", this, toString(time).utf8().data());
+    NOTICE_LOG(THIS, time);
     seekWithTolerance(time, MediaTime::zeroTime(), MediaTime::zeroTime(), false);
 }
 
@@ -2850,7 +2859,7 @@
     // already running. Abort that other instance of the algorithm without waiting for the step that
     // it is running to complete.
     if (m_seekTaskQueue.hasPendingTasks()) {
-        LOG(Media, "HTMLMediaElement::seekWithTolerance(%p) - cancelling pending seeks", this);
+        NOTICE_LOG(THIS, "cancelling pending seeks");
         m_seekTaskQueue.cancelAllTasks();
         if (m_pendingSeek) {
             now = m_pendingSeek->now;
@@ -2872,7 +2881,7 @@
     // the script. The remainder of these steps must be run asynchronously.
     m_pendingSeek = std::make_unique<PendingSeek>(now, time, negativeTolerance, positiveTolerance);
     if (fromDOM) {
-        LOG(Media, "HTMLMediaElement::seekWithTolerance(%p) - enqueuing seek from %s to %s", this, toString(now).utf8().data(), toString(time).utf8().data());
+        NOTICE_LOG(THIS, "enqueuing seek from ", now, " to ", time);
         m_seekTaskQueue.enqueueTask(std::bind(&HTMLMediaElement::seekTask, this));
     } else
         seekTask();
@@ -2883,7 +2892,7 @@
 
 void HTMLMediaElement::seekTask()
 {
-    LOG(Media, "HTMLMediaElement::seekTask(%p)", this);
+    NOTICE_LOG(THIS);
 
     if (!m_player) {
         clearSeeking();
@@ -2912,11 +2921,12 @@
     // time scale, we will ask the media engine to "seek" to the current movie time, which may be a noop and
     // not generate a timechanged callback. This means m_seeking will never be cleared and we will never
     // fire a 'seeked' event.
-#if !LOG_DISABLED
-    MediaTime mediaTime = m_player->mediaTimeForTimeValue(time);
-    if (time != mediaTime)
-        LOG(Media, "HTMLMediaElement::seekTask(%p) - %s - media timeline equivalent is %s", this, toString(time).utf8().data(), toString(mediaTime).utf8().data());
-#endif
+    if (willLog(WTFLogLevelDebug)) {
+        MediaTime mediaTime = m_player->mediaTimeForTimeValue(time);
+        if (time != mediaTime)
+            DEBUG_LOG(THIS, time, " media timeline equivalent is ", mediaTime);
+    }
+
     time = m_player->mediaTimeForTimeValue(time);
 
     // 8 - If the (possibly now changed) new playback position is not in one of the ranges given in the
@@ -2941,7 +2951,7 @@
 #endif
 
     if (noSeekRequired) {
-        LOG(Media, "HTMLMediaElement::seekTask(%p) - seek to %s ignored", this, toString(time).utf8().data());
+        NOTICE_LOG(THIS, "seek to ", time, " ignored");
         if (time == now) {
             scheduleEvent(eventNames().seekingEvent);
             scheduleTimeupdateEvent(false);
@@ -2983,7 +2993,7 @@
     // 14 - Set the seeking IDL attribute to false.
     clearSeeking();
 
-    LOG(Media, "HTMLMediaElement::finishSeek(%p) - current time = %s", this, toString(currentMediaTime()).utf8().data());
+    NOTICE_LOG(THIS, "current time = ", currentMediaTime());
 
     // 15 - Run the time maches on steps.
     // Handled by mediaPlayerTimeChanged().
@@ -3042,11 +3052,6 @@
     if (!m_player || !m_player->maximumDurationToCacheMediaTime())
         return;
 
-#if !LOG_DISABLED
-    if (m_cachedTime.isValid())
-        LOG(Media, "HTMLMediaElement::invalidateCachedTime(%p)", this);
-#endif
-
     // Don't try to cache movie time when playback first starts as the time reported by the engine
     // sometimes fluctuates for a short amount of time, so the cached time will be off if we take it
     // too early.
@@ -3071,7 +3076,7 @@
         return MediaTime::zeroTime();
 
     if (m_seeking) {
-        LOG(Media, "HTMLMediaElement::currentTime(%p) - seeking, returning %s", this, toString(m_lastSeekTime).utf8().data());
+        NOTICE_LOG(THIS, "seeking, returning", m_lastSeekTime);
         return m_lastSeekTime;
     }
 
@@ -3079,7 +3084,7 @@
 #if LOG_CACHED_TIME_WARNINGS
         MediaTime delta = m_cachedTime - m_player->currentTime();
         if (delta > minCachedDeltaForWarning)
-            LOG(Media, "HTMLMediaElement::currentTime(%p) - WARNING, cached time is %s seconds off of media time when paused", this, toString(delta).utf8().data());
+            WARNING_LOG(THIS, "cached time is ", delta, " seconds off of media time when paused");
 #endif
         return m_cachedTime;
     }
@@ -3098,7 +3103,7 @@
 #if LOG_CACHED_TIME_WARNINGS
             MediaTime delta = adjustedCacheTime - m_player->currentTime();
             if (delta > minCachedDeltaForWarning)
-                LOG(Media, "HTMLMediaElement::currentTime(%p) - WARNING, cached time is %f seconds off of media time when playing", this, delta);
+                WARNING_LOG(THIS, "cached time is ", delta, " seconds off of media time when playing");
 #endif
             return adjustedCacheTime;
         }
@@ -3108,7 +3113,7 @@
     if (maximumDurationToCacheMediaTime && now > m_minimumClockTimeToUpdateCachedTime && m_cachedTime != MediaPlayer::invalidTime()) {
         double clockDelta = now - m_clockTimeAtLastCachedTimeUpdate;
         MediaTime delta = m_cachedTime + MediaTime::createWithDouble(effectivePlaybackRate() * clockDelta) - m_player->currentTime();
-        LOG(Media, "HTMLMediaElement::currentTime(%p) - cached time was %s seconds off of media time when it expired", this, toString(delta).utf8().data());
+        WARNING_LOG(THIS, "cached time was ", delta, " seconds off of media time when it expired");
     }
 #endif
 
@@ -3193,11 +3198,12 @@
         return;
 #endif
 
-    if (m_defaultPlaybackRate != rate) {
-        LOG(Media, "HTMLMediaElement::setDefaultPlaybackRate(%p) - %f", this, rate);
-        m_defaultPlaybackRate = rate;
-        scheduleEvent(eventNames().ratechangeEvent);
-    }
+    if (m_defaultPlaybackRate == rate)
+        return;
+
+    ALWAYS_LOG(THIS, rate);
+    m_defaultPlaybackRate = rate;
+    scheduleEvent(eventNames().ratechangeEvent);
 }
 
 double HTMLMediaElement::effectivePlaybackRate() const
@@ -3226,7 +3232,7 @@
 
 void HTMLMediaElement::setPlaybackRate(double rate)
 {
-    LOG(Media, "HTMLMediaElement::setPlaybackRate(%p) - %f", this, rate);
+    ALWAYS_LOG(THIS, rate);
 
 #if ENABLE(MEDIA_STREAM)
     // http://w3c.github.io/mediacapture-main/#mediastreams-in-media-elements
@@ -3261,7 +3267,7 @@
 
 void HTMLMediaElement::setWebkitPreservesPitch(bool preservesPitch)
 {
-    LOG(Media, "HTMLMediaElement::setWebkitPreservesPitch(%p) - %s", this, boolString(preservesPitch));
+    NOTICE_LOG(THIS, preservesPitch);
 
     m_webkitPreservesPitch = preservesPitch;
 
@@ -3316,7 +3322,7 @@
 
 void HTMLMediaElement::setPreload(const String& preload)
 {
-    LOG(Media, "HTMLMediaElement::setPreload(%p) - %s", this, preload.utf8().data());
+    NOTICE_LOG(THIS, preload);
 #if ENABLE(MEDIA_STREAM)
     // http://w3c.github.io/mediacapture-main/#mediastreams-in-media-elements
     // "preload" - On getting: none. On setting: ignored.
@@ -3329,7 +3335,7 @@
 
 void HTMLMediaElement::play(DOMPromiseDeferred<void>&& promise)
 {
-    LOG(Media, "HTMLMediaElement::play(%p)", this);
+    ALWAYS_LOG(THIS);
 
     auto success = m_mediaSession->playbackPermitted(*this);
     if (!success) {
@@ -3357,7 +3363,7 @@
 
 void HTMLMediaElement::play()
 {
-    LOG(Media, "HTMLMediaElement::play(%p)", this);
+    ALWAYS_LOG(THIS);
 
     auto success = m_mediaSession->playbackPermitted(*this);
     if (!success) {
@@ -3373,10 +3379,10 @@
 
 bool HTMLMediaElement::playInternal()
 {
-    LOG(Media, "HTMLMediaElement::playInternal(%p)", this);
+    ALWAYS_LOG(THIS);
 
     if (!m_mediaSession->clientWillBeginPlayback()) {
-        LOG(Media, "  returning because of interruption");
+        ALWAYS_LOG(THIS, "  returning because of interruption");
         return true; // Treat as success because we will begin playback on cessation of the interruption.
     }
 
@@ -3445,7 +3451,7 @@
 
 void HTMLMediaElement::pause()
 {
-    LOG(Media, "HTMLMediaElement::pause(%p)", this);
+    ALWAYS_LOG(THIS);
 
     m_temporarilyAllowingInlinePlaybackAfterFullscreen = false;
 
@@ -3461,10 +3467,10 @@
 
 void HTMLMediaElement::pauseInternal()
 {
-    LOG(Media, "HTMLMediaElement::pauseInternal(%p)", this);
+    ALWAYS_LOG(THIS);
 
     if (!m_mediaSession->clientWillPausePlayback()) {
-        LOG(Media, "  returning because of interruption");
+        ALWAYS_LOG(THIS, "  returning because of interruption");
         return;
     }
 
@@ -3518,7 +3524,7 @@
 
 void HTMLMediaElement::setLoop(bool b)
 {
-    LOG(Media, "HTMLMediaElement::setLoop(%p) - %s", this, boolString(b));
+    NOTICE_LOG(THIS, b);
     setBooleanAttribute(loopAttr, b);
 }
 
@@ -3535,7 +3541,7 @@
 
 void HTMLMediaElement::setControls(bool b)
 {
-    LOG(Media, "HTMLMediaElement::setControls(%p) - %s", this, boolString(b));
+    NOTICE_LOG(THIS, b);
     setBooleanAttribute(controlsAttr, b);
 }
 
@@ -3546,7 +3552,7 @@
 
 ExceptionOr<void> HTMLMediaElement::setVolume(double volume)
 {
-    LOG(Media, "HTMLMediaElement::setVolume(%p) - %f", this, volume);
+    NOTICE_LOG(THIS, volume);
 
     if (!(volume >= 0 && volume <= 1))
         return Exception { IndexSizeError };
@@ -3570,7 +3576,7 @@
 
 void HTMLMediaElement::setMuted(bool muted)
 {
-    LOG(Media, "HTMLMediaElement::setMuted(%p) - %s", this, boolString(muted));
+    NOTICE_LOG(THIS, muted);
 
     bool mutedStateChanged = m_muted != muted;
     if (mutedStateChanged || !m_explicitlyMuted) {
@@ -3631,7 +3637,7 @@
 
 void HTMLMediaElement::togglePlayState()
 {
-    LOG(Media, "HTMLMediaElement::togglePlayState(%p) - canPlay() is %s", this, boolString(canPlay()));
+    NOTICE_LOG(THIS, "canPlay() is ", canPlay());
 
     // We can safely call the internal play/pause methods, which don't check restrictions, because
     // this method is only called from the built-in media controller
@@ -3644,7 +3650,7 @@
 
 void HTMLMediaElement::beginScrubbing()
 {
-    LOG(Media, "HTMLMediaElement::beginScrubbing(%p) - paused() is %s", this, boolString(paused()));
+    NOTICE_LOG(THIS, "paused() is ", paused());
 
     if (!paused()) {
         if (ended()) {
@@ -3665,7 +3671,7 @@
 
 void HTMLMediaElement::endScrubbing()
 {
-    LOG(Media, "HTMLMediaElement::endScrubbing(%p) - m_pausedInternal is %s", this, boolString(m_pausedInternal));
+    NOTICE_LOG(THIS, "m_pausedInternal is", m_pausedInternal);
 
     if (m_pausedInternal)
         setPausedInternal(false);
@@ -4034,13 +4040,6 @@
 {
     ASSERT(trackElement.hasTagName(trackTag));
 
-#if !LOG_DISABLED
-    if (trackElement.hasTagName(trackTag)) {
-        URL url = ""
-        LOG(Media, "HTMLMediaElement::didRemoveTrack(%p) - 'src' is %s", this, urlForLoggingMedia(url).utf8().data());
-    }
-#endif
-
     auto& textTrack = trackElement.track();
 
     textTrack.setHasBeenConfigured(false);
@@ -4061,8 +4060,6 @@
 {
     ASSERT(group.tracks.size());
 
-    LOG(Media, "HTMLMediaElement::configureTextTrackGroup(%p)", this);
-
     Page* page = document().page();
     CaptionUserPreferences* captionPreferences = page ? &page->group().captionPreferences() : 0;
     CaptionUserPreferences::CaptionDisplayMode displayMode = captionPreferences ? captionPreferences->captionDisplayMode() : CaptionUserPreferences::Automatic;
@@ -4091,7 +4088,7 @@
             currentlyEnabledTracks.append(textTrack);
 
         int trackScore = captionPreferences ? captionPreferences->textTrackSelectionScore(textTrack.get(), this) : 0;
-        LOG(Media, "HTMLMediaElement::configureTextTrackGroup(%p) -  '%s' track with language '%s' and BCP 47 language '%s' has score %d", this, textTrack->kindKeyword().string().utf8().data(), textTrack->language().string().utf8().data(), textTrack->validBCP47Language().string().utf8().data(), trackScore);
+        NOTICE_LOG(THIS, "'", textTrack->kindKeyword(), "' track with language '", textTrack->language(), "' and BCP 47 language '", textTrack->validBCP47Language(), "' has score ", trackScore);
 
         if (trackScore) {
 
@@ -4208,7 +4205,6 @@
 
 void HTMLMediaElement::updateCaptionContainer()
 {
-    LOG(Media, "HTMLMediaElement::updateCaptionContainer(%p)", this);
 #if ENABLE(MEDIA_CONTROLS_SCRIPT)
     if (m_haveSetUpCaptionContainer)
         return;
@@ -4421,18 +4417,15 @@
 URL HTMLMediaElement::selectNextSourceChild(ContentType* contentType, String* keySystem, InvalidURLAction actionIfInvalid)
 {
     UNUSED_PARAM(keySystem);
-#if !LOG_DISABLED
+
     // Don't log if this was just called to find out if there are any valid <source> elements.
-    bool shouldLog = actionIfInvalid != DoNothing;
+    bool shouldLog = willLog(WTFLogLevelDebug) && actionIfInvalid != DoNothing;
     if (shouldLog)
-        LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p)", this);
-#endif
+        NOTICE_LOG(THIS);
 
     if (!m_nextChildNodeToConsider) {
-#if !LOG_DISABLED
         if (shouldLog)
-            LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p) - end of list, stopping", this);
-#endif
+            NOTICE_LOG(THIS, "end of list, stopping");
         return URL();
     }
 
@@ -4451,18 +4444,14 @@
         // If candidate does not have a src attribute, or if its src attribute's value is the empty string ... jump down to the failed step below
         auto mediaURL = source->getNonEmptyURLAttribute(srcAttr);
         String type;
-#if !LOG_DISABLED
         if (shouldLog)
-            LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p) - 'src' is %s", this, urlForLoggingMedia(mediaURL).utf8().data());
-#endif
+            NOTICE_LOG(THIS, "'src' is ", mediaURL);
         if (mediaURL.isEmpty())
             goto CheckAgain;
 
         if (auto* media = source->parsedMediaAttribute()) {
-#if !LOG_DISABLED
             if (shouldLog)
-                LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p) - 'media' is %s", this, source->attributeWithoutSynchronization(mediaAttr).string().utf8().data());
-#endif
+                NOTICE_LOG(THIS, "'media' is ", source->attributeWithoutSynchronization(mediaAttr));
             auto* renderer = this->renderer();
             LOG(MediaQueries, "HTMLMediaElement %p selectNextSourceChild evaluating media queries", this);
             if (!MediaQueryEvaluator { "screen", document(), renderer ? &renderer->style() : nullptr }.evaluate(*media))
@@ -4473,10 +4462,8 @@
         if (type.isEmpty() && mediaURL.protocolIsData())
             type = mimeTypeFromDataURL(mediaURL);
         if (!type.isEmpty()) {
-#if !LOG_DISABLED
             if (shouldLog)
-                LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p) - 'type' is '%s'", this, type.utf8().data());
-#endif
+                NOTICE_LOG(THIS, "'type' is ", type);
             MediaEngineSupportParameters parameters;
             parameters.type = ContentType(type);
             parameters.url = ""
@@ -4499,7 +4486,7 @@
 
         // A 'beforeload' event handler can mutate the DOM, so check to see if the source element is still a child node.
         if (source->parentNode() != this) {
-            LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p) - 'beforeload' removed current element", this);
+            NOTICE_LOG(THIS, "'beforeload' removed current element");
             continue;
         }
 
@@ -4509,10 +4496,8 @@
         m_nextChildNodeToConsider = Traversal<HTMLSourceElement>::nextSkippingChildren(source);
         m_currentSourceNode = WTFMove(source);
 
-#if !LOG_DISABLED
         if (shouldLog)
-            LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p) -> %p, %s", this, m_currentSourceNode.get(), urlForLoggingMedia(mediaURL).utf8().data());
-#endif
+            NOTICE_LOG(THIS, " = ", mediaURL);
 
         return mediaURL;
 
@@ -4526,7 +4511,7 @@
 
 #if !LOG_DISABLED
     if (shouldLog)
-        LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p) -> %p, failed", this, m_currentSourceNode.get());
+        NOTICE_LOG(THIS, "failed");
 #endif
     return URL();
 }
@@ -4533,14 +4518,10 @@
 
 void HTMLMediaElement::sourceWasAdded(HTMLSourceElement& source)
 {
-    LOG(Media, "HTMLMediaElement::sourceWasAdded(%p) - %p", this, &source);
-
-#if !LOG_DISABLED
-    if (source.hasTagName(sourceTag)) {
+    if (willLog(WTFLogLevelNotice) && source.hasTagName(sourceTag)) {
         URL url = ""
-        LOG(Media, "HTMLMediaElement::sourceWasAdded(%p) - 'src' is %s", this, urlForLoggingMedia(url).utf8().data());
+        NOTICE_LOG(THIS, "'src' is ", url);
     }
-#endif
 
     // We should only consider a <source> element when there is not src attribute at all.
     if (hasAttributeWithoutSynchronization(srcAttr))
@@ -4559,7 +4540,7 @@
     }
 
     if (m_currentSourceNode && &source == Traversal<HTMLSourceElement>::nextSibling(*m_currentSourceNode)) {
-        LOG(Media, "HTMLMediaElement::sourceWasAdded(%p) - <source> inserted immediately after current source", this);
+        NOTICE_LOG(THIS, "<source> inserted immediately after current source");
         m_nextChildNodeToConsider = &source;
         return;
     }
@@ -4584,14 +4565,10 @@
 
 void HTMLMediaElement::sourceWasRemoved(HTMLSourceElement& source)
 {
-    LOG(Media, "HTMLMediaElement::sourceWasRemoved(%p) - %p", this, &source);
-
-#if !LOG_DISABLED
-    if (source.hasTagName(sourceTag)) {
+    if (willLog(WTFLogLevelNotice) && source.hasTagName(sourceTag)) {
         URL url = ""
-        LOG(Media, "HTMLMediaElement::sourceWasRemoved(%p) - 'src' is %s", this, urlForLoggingMedia(url).utf8().data());
+        NOTICE_LOG(THIS, "'src' is ", url);
     }
-#endif
 
     if (&source != m_currentSourceNode && &source != m_nextChildNodeToConsider)
         return;
@@ -4598,19 +4575,19 @@
 
     if (&source == m_nextChildNodeToConsider) {
         m_nextChildNodeToConsider = m_currentSourceNode ? Traversal<HTMLSourceElement>::nextSibling(*m_currentSourceNode) : nullptr;
-        LOG(Media, "HTMLMediaElement::sourceRemoved(%p) - m_nextChildNodeToConsider set to %p", this, m_nextChildNodeToConsider.get());
+        NOTICE_LOG(THIS);
     } else if (&source == m_currentSourceNode) {
         // Clear the current source node pointer, but don't change the movie as the spec says:
         // 4.8.8 - Dynamically modifying a source element and its attribute when the element is already
         // inserted in a video or audio element will have no effect.
         m_currentSourceNode = nullptr;
-        LOG(Media, "HTMLMediaElement::sourceRemoved(%p) - m_currentSourceNode set to 0", this);
+        NOTICE_LOG(THIS, "m_currentSourceNode set to 0");
     }
 }
 
 void HTMLMediaElement::mediaPlayerTimeChanged(MediaPlayer*)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerTimeChanged(%p)", this);
+    NOTICE_LOG(THIS);
 
 #if ENABLE(VIDEO_TRACK)
     updateActiveTextTrackCues(currentMediaTime());
@@ -4738,7 +4715,7 @@
 
 void HTMLMediaElement::mediaPlayerVolumeChanged(MediaPlayer*)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerVolumeChanged(%p)", this);
+    NOTICE_LOG(THIS);
 
     beginProcessingMediaPlayerCallback();
     if (m_player) {
@@ -4754,7 +4731,7 @@
 
 void HTMLMediaElement::mediaPlayerMuteChanged(MediaPlayer*)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerMuteChanged(%p)", this);
+    NOTICE_LOG(THIS);
 
     beginProcessingMediaPlayerCallback();
     if (m_player)
@@ -4764,7 +4741,7 @@
 
 void HTMLMediaElement::mediaPlayerDurationChanged(MediaPlayer* player)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerDurationChanged(%p)", this);
+    NOTICE_LOG(THIS);
 
     beginProcessingMediaPlayerCallback();
 
@@ -4787,7 +4764,7 @@
     // using (eg. it can't handle the rate we set)
     m_reportedPlaybackRate = m_player->rate();
 
-    LOG(Media, "HTMLMediaElement::mediaPlayerRateChanged(%p) - rate: %lf", this, m_reportedPlaybackRate);
+    NOTICE_LOG(THIS, "rate: ", m_reportedPlaybackRate);
 
     if (m_playing)
         invalidateCachedTime();
@@ -4799,7 +4776,7 @@
 
 void HTMLMediaElement::mediaPlayerPlaybackStateChanged(MediaPlayer*)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerPlaybackStateChanged(%p)", this);
+    NOTICE_LOG(THIS);
 
     if (!m_player || m_pausedInternal)
         return;
@@ -4814,7 +4791,7 @@
 
 void HTMLMediaElement::mediaPlayerSawUnsupportedTracks(MediaPlayer*)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerSawUnsupportedTracks(%p)", this);
+    NOTICE_LOG(THIS);
 
     // The MediaPlayer came across content it cannot completely handle.
     // This is normally acceptable except when we are in a standalone
@@ -4825,7 +4802,7 @@
 
 void HTMLMediaElement::mediaPlayerResourceNotSupported(MediaPlayer*)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerResourceNotSupported(%p)", this);
+    NOTICE_LOG(THIS);
 
     // The MediaPlayer came across content which no installed engine supports.
     mediaLoadingFailed(MediaPlayer::FormatError);
@@ -4843,7 +4820,7 @@
 
 void HTMLMediaElement::mediaPlayerSizeChanged(MediaPlayer*)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerSizeChanged(%p)", this);
+    NOTICE_LOG(THIS);
 
     if (is<MediaDocument>(document()) && m_player)
         downcast<MediaDocument>(document()).mediaElementNaturalSizeChanged(expandedIntSize(m_player->naturalSize()));
@@ -4864,7 +4841,7 @@
 
 void HTMLMediaElement::mediaPlayerRenderingModeChanged(MediaPlayer*)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerRenderingModeChanged(%p)", this);
+    NOTICE_LOG(THIS);
 
     // Kick off a fake recalcStyle that will update the compositing tree.
     invalidateStyleAndLayerComposition();
@@ -4889,7 +4866,7 @@
 
 void HTMLMediaElement::mediaEngineWasUpdated()
 {
-    LOG(Media, "HTMLMediaElement::mediaEngineWasUpdated(%p)", this);
+    NOTICE_LOG(THIS);
     beginProcessingMediaPlayerCallback();
     updateRenderer();
     endProcessingMediaPlayerCallback();
@@ -4919,7 +4896,7 @@
 
 void HTMLMediaElement::mediaPlayerEngineUpdated(MediaPlayer*)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerEngineUpdated(%p)", this);
+    NOTICE_LOG(THIS);
 
 #if ENABLE(MEDIA_SOURCE)
     m_droppedVideoFrames = 0;
@@ -4932,7 +4909,7 @@
 
 void HTMLMediaElement::mediaPlayerFirstVideoFrameAvailable(MediaPlayer*)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerFirstVideoFrameAvailable(%p) - current display mode = %i", this, (int)displayMode());
+    NOTICE_LOG(THIS, "current display mode = ", (int)displayMode());
 
     beginProcessingMediaPlayerCallback();
     if (displayMode() == PosterWaitingForVideo) {
@@ -4944,7 +4921,7 @@
 
 void HTMLMediaElement::mediaPlayerCharacteristicChanged(MediaPlayer*)
 {
-    LOG(Media, "HTMLMediaElement::mediaPlayerCharacteristicChanged(%p)", this);
+    NOTICE_LOG(THIS);
 
     beginProcessingMediaPlayerCallback();
 
@@ -5194,7 +5171,7 @@
     bool shouldBePlaying = potentiallyPlaying();
     bool playerPaused = m_player->paused();
 
-    LOG(Media, "HTMLMediaElement::updatePlayState(%p) - shouldBePlaying = %s, playerPaused = %s", this, boolString(shouldBePlaying), boolString(playerPaused));
+    NOTICE_LOG(THIS, "shouldBePlaying = ", shouldBePlaying, " playerPaused = ", playerPaused);
 
     if (shouldBePlaying) {
         scheduleUpdatePlaybackControlsManager();
@@ -5290,7 +5267,7 @@
 
 void HTMLMediaElement::userCancelledLoad()
 {
-    LOG(Media, "HTMLMediaElement::userCancelledLoad(%p)", this);
+    NOTICE_LOG(THIS);
 
     // FIXME: We should look to reconcile the iOS and non-iOS code (below).
 #if PLATFORM(IOS)
@@ -5343,7 +5320,7 @@
 
 void HTMLMediaElement::clearMediaPlayer(DelayedActionType flags)
 {
-    LOG(Media, "HTMLMediaElement::clearMediaPlayer(%p) - flags = %s", this, actionName(flags).utf8().data());
+    NOTICE_LOG(THIS, "flags = ", actionName(flags));
 
 #if ENABLE(MEDIA_STREAM)
     if (!m_settingMediaStreamSrcObject)
@@ -5418,7 +5395,7 @@
 
 void HTMLMediaElement::stopWithoutDestroyingMediaPlayer()
 {
-    LOG(Media, "HTMLMediaElement::stopWithoutDestroyingMediaPlayer(%p)", this);
+    NOTICE_LOG(THIS);
 
     if (m_videoFullscreenMode != VideoFullscreenModeNone)
         exitFullscreen();
@@ -5462,7 +5439,7 @@
 
 void HTMLMediaElement::stop()
 {
-    LOG(Media, "HTMLMediaElement::stop(%p)", this);
+    NOTICE_LOG(THIS);
 
     Ref<HTMLMediaElement> protectedThis(*this);
     stopWithoutDestroyingMediaPlayer();
@@ -5482,7 +5459,7 @@
 
 void HTMLMediaElement::suspend(ReasonForSuspension why)
 {
-    LOG(Media, "HTMLMediaElement::suspend(%p)", this);
+    NOTICE_LOG(THIS);
     Ref<HTMLMediaElement> protectedThis(*this);
 
     switch (why)
@@ -5503,7 +5480,7 @@
 
 void HTMLMediaElement::resume()
 {
-    LOG(Media, "HTMLMediaElement::resume(%p)", this);
+    NOTICE_LOG(THIS);
 
     m_inActiveDocument = true;
 
@@ -5537,7 +5514,7 @@
 
 void HTMLMediaElement::mediaVolumeDidChange()
 {
-    LOG(Media, "HTMLMediaElement::mediaVolumeDidChange(%p)", this);
+    NOTICE_LOG(THIS);
     updateVolume();
 }
 
@@ -5544,7 +5521,7 @@
 void HTMLMediaElement::visibilityStateChanged()
 {
     m_elementIsHidden = document().hidden() && m_videoFullscreenMode != VideoFullscreenModePictureInPicture;
-    LOG(Media, "HTMLMediaElement::visibilityStateChanged(%p) - visible = %s", this, boolString(!m_elementIsHidden));
+    NOTICE_LOG(THIS, "visible = ", !m_elementIsHidden);
     updateSleepDisabling();
     m_mediaSession->visibilityChanged();
     if (m_player)
@@ -5553,10 +5530,10 @@
     bool isPlayingAudio = isPlaying() && hasAudio() && !muted() && volume();
     if (!isPlayingAudio) {
         if (m_elementIsHidden) {
-            RELEASE_LOG_IF_ALLOWED("visibilityStateChanged() Suspending playback after going to the background");
+            ALWAYS_LOG(THIS, "visibilityStateChanged() Suspending playback after going to the background");
             m_mediaSession->beginInterruption(PlatformMediaSession::EnteringBackground);
         } else {
-            RELEASE_LOG_IF_ALLOWED("visibilityStateChanged() Resuming playback after entering foreground");
+            ALWAYS_LOG(THIS, "visibilityStateChanged() Resuming playback after entering foreground");
             m_mediaSession->endInterruption(PlatformMediaSession::MayResumePlaying);
         }
     }
@@ -5584,7 +5561,7 @@
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
 void HTMLMediaElement::webkitShowPlaybackTargetPicker()
 {
-    LOG(Media, "HTMLMediaElement::webkitShowPlaybackTargetPicker(%p)", this);
+    NOTICE_LOG(THIS);
     if (processingUserGestureForMedia())
         removeBehaviorsRestrictionsAfterFirstUserGesture();
     m_mediaSession->showPlaybackTargetPicker(*this);
@@ -5604,7 +5581,7 @@
 {
     m_isPlayingToWirelessTarget = m_player && m_player->isCurrentPlaybackTargetWireless();
 
-    LOG(Media, "HTMLMediaElement::mediaPlayerCurrentPlaybackTargetIsWirelessChanged(%p) - webkitCurrentPlaybackTargetIsWireless = %s", this, boolString(m_isPlayingToWirelessTarget));
+    NOTICE_LOG(THIS, "webkitCurrentPlaybackTargetIsWireless = ", m_isPlayingToWirelessTarget);
     ASSERT(m_player);
     configureMediaControls();
     scheduleEvent(eventNames().webkitcurrentplaybacktargetiswirelesschangedEvent);
@@ -5620,6 +5597,9 @@
         m_failedToPlayToWirelessTarget = false;
         scheduleDelayedAction(CheckPlaybackTargetCompatablity);
     }
+
+    DEBUG_LOG(THIS, "dispatching '", event.type(), "'");
+
     return HTMLElement::dispatchEvent(event);
 }
 
@@ -5637,7 +5617,7 @@
         m_mediaSession->setHasPlaybackTargetAvailabilityListeners(*this, true);
     }
 
-    LOG(Media, "HTMLMediaElement::addEventListener(%p) - 'webkitplaybacktargetavailabilitychanged'", this);
+    NOTICE_LOG(THIS, "'webkitplaybacktargetavailabilitychanged'");
 
     enqueuePlaybackTargetAvailabilityChangedEvent(); // Ensure the event listener gets at least one event.
     return true;
@@ -5652,7 +5632,7 @@
         return false;
 
     bool didRemoveLastAvailabilityChangedListener = !hasEventListeners(eventNames().webkitplaybacktargetavailabilitychangedEvent);
-    LOG(Media, "HTMLMediaElement::removeEventListener(%p) - removed last listener = %s", this, boolString(didRemoveLastAvailabilityChangedListener));
+    NOTICE_LOG(THIS, "removed last listener = ", didRemoveLastAvailabilityChangedListener);
     if (didRemoveLastAvailabilityChangedListener) {
         m_hasPlaybackTargetAvailabilityListeners = false;
         m_mediaSession->setHasPlaybackTargetAvailabilityListeners(*this, false);
@@ -5665,7 +5645,7 @@
 void HTMLMediaElement::enqueuePlaybackTargetAvailabilityChangedEvent()
 {
     bool hasTargets = m_mediaSession->hasWirelessPlaybackTargets(*this);
-    LOG(Media, "HTMLMediaElement::enqueuePlaybackTargetAvailabilityChangedEvent(%p) - hasTargets = %s", this, boolString(hasTargets));
+    NOTICE_LOG(THIS, "hasTargets = ", hasTargets);
     auto event = WebKitPlaybackTargetAvailabilityEvent::create(eventNames().webkitplaybacktargetavailabilitychangedEvent, hasTargets);
     event->setTarget(this);
     m_asyncEventQueue.enqueueEvent(WTFMove(event));
@@ -5674,7 +5654,7 @@
 
 void HTMLMediaElement::setWirelessPlaybackTarget(Ref<MediaPlaybackTarget>&& device)
 {
-    LOG(Media, "HTMLMediaElement::setWirelessPlaybackTarget(%p)", this);
+    NOTICE_LOG(THIS);
     if (m_player)
         m_player->setWirelessPlaybackTarget(WTFMove(device));
 }
@@ -5683,7 +5663,7 @@
 {
     bool canPlay = m_player && m_player->canPlayToWirelessPlaybackTarget();
 
-    LOG(Media, "HTMLMediaElement::canPlayToWirelessPlaybackTarget(%p) - returning %s", this, boolString(canPlay));
+    NOTICE_LOG(THIS, "returning ", canPlay);
 
     return canPlay;
 }
@@ -5695,7 +5675,7 @@
 
 void HTMLMediaElement::setShouldPlayToPlaybackTarget(bool shouldPlay)
 {
-    LOG(Media, "HTMLMediaElement::setShouldPlayToPlaybackTarget(%p) - shouldPlay = %s", this, boolString(shouldPlay));
+    NOTICE_LOG(THIS, "shouldPlay = ", shouldPlay);
 
     if (m_player)
         m_player->setShouldPlayToPlaybackTarget(shouldPlay);
@@ -5744,8 +5724,6 @@
 
 void HTMLMediaElement::toggleStandardFullscreenState()
 {
-    LOG(Media, "HTMLMediaElement::toggleStandardFullscreenState(%p) - isStandardFullscreen() is %s", this, boolString(isStandardFullscreen()));
-
     if (isStandardFullscreen())
         exitFullscreen();
     else
@@ -5754,7 +5732,7 @@
 
 void HTMLMediaElement::enterFullscreen(VideoFullscreenMode mode)
 {
-    LOG(Media, "HTMLMediaElement::enterFullscreen(%p)", this);
+    NOTICE_LOG(THIS);
     ASSERT(mode != VideoFullscreenModeNone);
 
     if (m_videoFullscreenMode == mode)
@@ -5799,7 +5777,7 @@
 
 void HTMLMediaElement::exitFullscreen()
 {
-    LOG(Media, "HTMLMediaElement::exitFullscreen(%p)", this);
+    NOTICE_LOG(THIS);
 
 #if ENABLE(FULLSCREEN_API)
     if (document().settings().fullScreenEnabled() && document().webkitCurrentFullScreenElement() == this) {
@@ -6005,7 +5983,7 @@
 
 void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible)
 {
-    LOG(Media, "HTMLMediaElement::setClosedCaptionsVisible(%p) - %s", this, boolString(closedCaptionVisible));
+    NOTICE_LOG(THIS, closedCaptionVisible);
 
     m_closedCaptionsVisible = false;
 
@@ -6060,8 +6038,7 @@
 void HTMLMediaElement::mediaCanStart(Document& document)
 {
     ASSERT_UNUSED(document, &document == &this->document());
-    LOG(Media, "HTMLMediaElement::mediaCanStart(%p) - m_isWaitingUntilMediaCanStart = %s, m_pausedInternal = %s",
-        this, boolString(m_isWaitingUntilMediaCanStart), boolString(m_pausedInternal) );
+    NOTICE_LOG(THIS, "m_isWaitingUntilMediaCanStart = ", m_isWaitingUntilMediaCanStart, ", m_pausedInternal = ", m_pausedInternal);
 
     ASSERT(m_isWaitingUntilMediaCanStart || m_pausedInternal);
     if (m_isWaitingUntilMediaCanStart) {
@@ -6082,7 +6059,7 @@
     if (m_shouldDelayLoadEvent == shouldDelay)
         return;
 
-    LOG(Media, "HTMLMediaElement::setShouldDelayLoadEvent(%p) - %s", this, boolString(shouldDelay));
+    NOTICE_LOG(THIS, shouldDelay);
 
     m_shouldDelayLoadEvent = shouldDelay;
     if (shouldDelay)
@@ -6133,7 +6110,6 @@
         return;
 
     bool privateMode = document().page() && document().page()->usesEphemeralSession();
-    LOG(Media, "HTMLMediaElement::privateBrowsingStateDidChange(%p) - %s", this, boolString(privateMode));
     m_player->setPrivateBrowsingMode(privateMode);
 }
 
@@ -6315,7 +6291,7 @@
     if (!m_textTracks)
         return;
 
-    LOG(Media, "HTMLMediaElement::markCaptionAndSubtitleTracksAsUnconfigured(%p)", this);
+    NOTICE_LOG(THIS);
 
     // Mark all tracks as not "configured" so that configureTextTracks()
     // will reconsider which tracks to display in light of new user preferences
@@ -6341,7 +6317,7 @@
 
 void HTMLMediaElement::createMediaPlayer()
 {
-    LOG(Media, "HTMLMediaElement::createMediaPlayer(%p)", this);
+    NOTICE_LOG(THIS);
 
 #if ENABLE(WEB_AUDIO)
     if (m_audioSourceNode)
@@ -6947,7 +6923,7 @@
 
 bool HTMLMediaElement::ensureMediaControlsInjectedScript()
 {
-    LOG(Media, "HTMLMediaElement::ensureMediaControlsInjectedScript(%p)", this);
+    DEBUG_LOG(THIS);
     Page* page = document().page();
     if (!page)
         return false;
@@ -7024,7 +7000,7 @@
 
 void HTMLMediaElement::didAddUserAgentShadowRoot(ShadowRoot* root)
 {
-    LOG(Media, "HTMLMediaElement::didAddUserAgentShadowRoot(%p)", this);
+    DEBUG_LOG(THIS);
 
     Page* page = document().page();
     if (!page)
@@ -7107,10 +7083,10 @@
 
 void HTMLMediaElement::setMediaControlsDependOnPageScaleFactor(bool dependsOnPageScale)
 {
-    LOG(Media, "MediaElement::setMediaControlsDependPageScaleFactor(%p) = %s", this, boolString(dependsOnPageScale));
+    DEBUG_LOG(THIS, "MediaElement::setMediaControlsDependPageScaleFactor", dependsOnPageScale);
 
     if (document().settings().mediaControlsScaleWithPageZoom()) {
-        LOG(Media, "MediaElement::setMediaControlsDependPageScaleFactor(%p) forced to false by Settings value", this);
+        DEBUG_LOG(THIS, "MediaElement::setMediaControlsDependPageScaleFactor", "forced to false by Settings value");
         m_mediaControlsDependOnPageScaleFactor = false;
         return;
     }
@@ -7291,7 +7267,7 @@
 
 void HTMLMediaElement::suspendPlayback()
 {
-    LOG(Media, "HTMLMediaElement::suspendPlayback(%p) - paused = %s", this, boolString(paused()));
+    NOTICE_LOG(THIS, "paused = ", paused());
     if (!paused())
         pause();
 }
@@ -7298,7 +7274,7 @@
 
 void HTMLMediaElement::resumeAutoplaying()
 {
-    LOG(Media, "HTMLMediaElement::resumeAutoplaying(%p) - paused = %s", this, boolString(paused()));
+    NOTICE_LOG(THIS, "paused = ", paused());
     m_autoplaying = true;
 
     if (canTransitionFromAutoplayToPlay())
@@ -7307,7 +7283,7 @@
 
 void HTMLMediaElement::mayResumePlayback(bool shouldResume)
 {
-    LOG(Media, "HTMLMediaElement::mayResumePlayback(%p) - paused = %s", this, boolString(paused()));
+    NOTICE_LOG(THIS, "paused = ", paused());
     if (paused() && shouldResume)
         play();
 }
@@ -7322,7 +7298,7 @@
 
 void HTMLMediaElement::didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType command, const PlatformMediaSession::RemoteCommandArgument* argument)
 {
-    LOG(Media, "HTMLMediaElement::didReceiveRemoteControlCommand(%p) - %i", this, static_cast<int>(command));
+    NOTICE_LOG(THIS, static_cast<int>(command));
 
     UserGestureIndicator remoteControlUserGesture(ProcessingUserGesture, &document());
     switch (command) {
@@ -7375,7 +7351,7 @@
     if (type == PlatformMediaSession::EnteringBackground) {
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
         if (m_isPlayingToWirelessTarget) {
-            LOG(Media, "HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction(%p) - returning true because m_isPlayingToWirelessTarget is true", this);
+            NOTICE_LOG(THIS, "returning true because m_isPlayingToWirelessTarget is true");
             return true;
         }
 #endif
@@ -7388,7 +7364,7 @@
     } else if (type == PlatformMediaSession::SuspendedUnderLock) {
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
         if (m_isPlayingToWirelessTarget) {
-            LOG(Media, "HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction(%p) - returning true because m_isPlayingToWirelessTarget is true", this);
+            NOTICE_LOG(THIS, "returning true because m_isPlayingToWirelessTarget is true");
             return true;
         }
 #endif
@@ -7549,7 +7525,7 @@
         return;
 
     if (m_isPlayingToWirelessTarget) {
-        LOG(Media, "HTMLMediaElement::purgeBufferedDataIfPossible(%p) - early return because m_isPlayingToWirelessTarget is true", this);
+        NOTICE_LOG(THIS, "early return because playing to wireless target");
         return;
     }
 
@@ -7556,6 +7532,7 @@
     // This is called to relieve memory pressure. Turning off buffering causes the media playback
     // daemon to release memory associated with queued-up video frames.
     // We turn it back on right away, but new frames won't get loaded unless playback is resumed.
+    NOTICE_LOG(THIS, "toggling data buffering");
     setShouldBufferData(false);
     setShouldBufferData(true);
 #endif
@@ -7755,6 +7732,23 @@
     scheduleUpdatePlaybackControlsManager();
 }
 
+#if !RELEASE_LOG_DISABLED
+WTFLogChannel& HTMLMediaElement::logChannel() const
+{
+    return LogMedia;
 }
+#endif
 
+bool HTMLMediaElement::willLog(WTFLogLevel level) const
+{
+#if !RELEASE_LOG_DISABLED
+    return m_logger->willLog(logChannel(), level);
+#else
+    UNUSED_PARAM(level);
+    return false;
 #endif
+}
+
+}
+
+#endif

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (221493 => 221494)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2017-09-01 20:40:11 UTC (rev 221494)
@@ -38,6 +38,7 @@
 #include "MediaElementSession.h"
 #include "MediaProducer.h"
 #include "VisibilityChangeClient.h"
+#include <pal/LoggerHelper.h>
 #include <wtf/Function.h>
 #include <wtf/WeakPtr.h>
 
@@ -64,6 +65,7 @@
 #endif
 
 namespace PAL {
+class Logger;
 class SleepDisabler;
 }
 
@@ -138,6 +140,9 @@
 #if ENABLE(ENCRYPTED_MEDIA)
     , private CDMClient
 #endif
+#if !RELEASE_LOG_DISABLED
+    , private PAL::LoggerHelper
+#endif
 {
 public:
     WeakPtr<HTMLMediaElement> createWeakPtr() { return m_weakFactory.createWeakPtr(); }
@@ -889,6 +894,14 @@
     void handleSeekToPlaybackPosition(double);
     void seekToPlaybackPositionEndedTimerFired();
 
+#if !RELEASE_LOG_DISABLED
+    const PAL::Logger& logger() const final { return *m_logger.get(); }
+    const char* className() const final { return "HTMLMediaElement"; }
+    WTFLogChannel& logChannel() const final;
+#endif
+
+    bool willLog(WTFLogLevel) const;
+
     WeakPtrFactory<HTMLMediaElement> m_weakFactory;
     Timer m_pendingActionTimer;
     Timer m_progressEventTimer;
@@ -1106,6 +1119,10 @@
     std::unique_ptr<MediaElementSession> m_mediaSession;
     size_t m_reportedExtraMemoryCost { 0 };
 
+#if !RELEASE_LOG_DISABLED
+    RefPtr<PAL::Logger> m_logger;
+#endif
+
 #if ENABLE(MEDIA_CONTROLS_SCRIPT)
     friend class MediaControlsHost;
     RefPtr<MediaControlsHost> m_mediaControlsHost;

Modified: trunk/Tools/ChangeLog (221493 => 221494)


--- trunk/Tools/ChangeLog	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Tools/ChangeLog	2017-09-01 20:40:11 UTC (rev 221494)
@@ -1,3 +1,13 @@
+2017-09-01  Eric Carlson  <eric.carl...@apple.com>
+
+        Switch HTMLMediaElement to release logging
+        https://bugs.webkit.org/show_bug.cgi?id=176065
+
+        Reviewed by Jer Noble.
+
+        * TestWebKitAPI/Tests/WebCore/Logging.cpp:
+        (TestWebKitAPI::LogObserver::level const):
+
 2017-09-01  Ross Kirsling  <ross.kirsl...@sony.com>
 
         download-latest-github-release.py should have friendlier output for non-404 errors

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/Logging.cpp (221493 => 221494)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/Logging.cpp	2017-09-01 19:47:53 UTC (rev 221493)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/Logging.cpp	2017-09-01 20:40:11 UTC (rev 221494)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "WTFStringUtilities.h"
 #include <pal/Logger.h>
+#include <pal/LoggerHelper.h>
 #include <wtf/Assertions.h>
 #include <wtf/MainThread.h>
 
@@ -51,11 +52,11 @@
 
 // Define the following to enable all tests. Disabled by default because replacing stderr with a
 // non-blocking pipe fails on some of the bots.
-#define TEST_OUTPUT 0
+#define TEST_OUTPUT 1
 
 namespace TestWebKitAPI {
 
-class LoggingTest : public testing::Test, public LogHelper {
+class LoggingTest : public testing::Test, public LoggerHelper {
 public:
     LoggingTest()
         : m_logger { Logger::create(this) }
@@ -335,7 +336,7 @@
     EXPECT_TRUE(output().contains("String and const String", false));
 }
 
-TEST_F(LoggingTest, LogHelper)
+TEST_F(LoggingTest, LoggerHelper)
 {
     EXPECT_TRUE(logger().enabled());
 
@@ -345,30 +346,29 @@
     builder.appendLiteral(")");
     String signature = builder.toString();
 
-    ALWAYS_LOG();
+    ALWAYS_LOG(THIS);
     EXPECT_TRUE(this->output().contains(signature, false));
 
-    ALWAYS_LOG("Welcome back", " my friends", " to the show", " that never ends");
+    ALWAYS_LOG(THIS, "Welcome back", " my friends", " to the show", " that never ends");
     String result = this->output();
     EXPECT_TRUE(result.contains(signature, false));
     EXPECT_TRUE(result.contains("to the show that never", false));
 
     WTFSetLogChannelLevel(&TestChannel1, WTFLogLevelWarning);
-    EXPECT_TRUE(willLog(WTFLogLevelWarning));
 
-    ERROR_LOG("We're so glad you could attend");
+    ERROR_LOG(THIS, "We're so glad you could attend");
     EXPECT_TRUE(output().contains("We're so glad you could attend", false));
 
-    WARNING_LOG("Come inside! ", "Come inside!");
+    WARNING_LOG(THIS, "Come inside! ", "Come inside!");
     EXPECT_TRUE(output().contains("Come inside! Come inside!", false));
 
-    NOTICE_LOG("There behind a glass is a real blade of grass");
+    NOTICE_LOG(THIS, "There behind a glass is a real blade of grass");
     EXPECT_EQ(0u, output().length());
 
-    INFO_LOG("be careful as you pass.");
+    INFO_LOG(THIS, "be careful as you pass.");
     EXPECT_EQ(0u, output().length());
 
-    DEBUG_LOG("Move along! Move along!");
+    DEBUG_LOG(THIS, "Move along! Move along!");
     EXPECT_EQ(0u, output().length());
 }
 
@@ -385,18 +385,22 @@
     }
 
     WTFLogChannel channel() const { return m_lastChannel; }
+    WTFLogLevel level() const { return m_lastLevel; }
 
 private:
-    void didLogMessage(const WTFLogChannel& channel, const String& logMessage) final
+    void didLogMessage(const WTFLogChannel& channel, WTFLogLevel level, const String& logMessage) final
     {
         m_logBuffer.append(logMessage);
         m_lastChannel = channel;
+        m_lastLevel = level;
     }
 
     StringBuilder m_logBuffer;
     WTFLogChannel m_lastChannel;
+    WTFLogLevel m_lastLevel { WTFLogLevelError };
 };
 
+#if !RELEASE_LOG_DISABLED
 TEST_F(LoggingTest, LogObserver)
 {
     LogObserver observer;
@@ -404,10 +408,11 @@
     EXPECT_TRUE(logger().enabled());
 
     logger().addObserver(observer);
-    ALWAYS_LOG("testing 1, 2, 3");
+    ALWAYS_LOG(THIS, "testing 1, 2, 3");
     EXPECT_TRUE(this->output().contains("testing 1, 2, 3", false));
     EXPECT_TRUE(observer.log().contains("testing 1, 2, 3", false));
     EXPECT_STREQ(observer.channel().name, logChannel().name);
+    EXPECT_EQ(static_cast<int>(WTFLogLevelAlways), static_cast<int>(observer.level()));
 
     logger().removeObserver(observer);
     ALWAYS_LOG("testing ", 1, ", ", 2, ", 3");
@@ -414,6 +419,7 @@
     EXPECT_TRUE(this->output().contains("testing 1, 2, 3", false));
     EXPECT_EQ(0u, observer.log().length());
 }
+#endif
 
 #endif
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to