Add AggregateLogger, a Logger specialization for singleton classes.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Mar 2019 20:18:08 +0000 (20:18 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Mar 2019 20:18:08 +0000 (20:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195644

Reviewed by Eric Carlson.

Source/WebCore:

Convert debug logging over to release logging through the use of AggregateLogger.

* platform/audio/PlatformMediaSession.h:
(WebCore::PlatformMediaSession::client const):
* platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::PlatformMediaSessionManager):
(WebCore::PlatformMediaSessionManager::beginInterruption):
(WebCore::PlatformMediaSessionManager::endInterruption):
(WebCore::PlatformMediaSessionManager::addSession):
(WebCore::PlatformMediaSessionManager::removeSession):
(WebCore::PlatformMediaSessionManager::sessionWillBeginPlayback):
(WebCore::PlatformMediaSessionManager::sessionWillEndPlayback):
(WebCore::PlatformMediaSessionManager::setCurrentSession):
(WebCore::PlatformMediaSessionManager::applicationWillBecomeInactive const):
(WebCore::PlatformMediaSessionManager::applicationDidBecomeActive const):
(WebCore::PlatformMediaSessionManager::applicationDidEnterBackground const):
(WebCore::PlatformMediaSessionManager::applicationWillEnterForeground const):
(WebCore::PlatformMediaSessionManager::logChannel const):
* platform/audio/PlatformMediaSessionManager.h:
* platform/audio/cocoa/MediaSessionManagerCocoa.mm:
(MediaSessionManagerCocoa::updateSessionState):
(MediaSessionManagerCocoa::sessionWillBeginPlayback):
(MediaSessionManagerCocoa::removeSession):
(MediaSessionManagerCocoa::sessionWillEndPlayback):
(MediaSessionManagerCocoa::clientCharacteristicsChanged):
(MediaSessionManagerCocoa::updateNowPlayingInfo):
* platform/audio/ios/MediaSessionManagerIOS.mm:
(WebCore::MediaSessionManageriOS::resetRestrictions):
(WebCore::MediaSessionManageriOS::configureWireLessTargetMonitoring):

Source/WTF:

Add a new class, AggregateLogger, which will log messages to each of its aggregated loggers.

Drive-by fixes: allow "const void*" to be directly logged by converting the pointer to a hex string.

* WTF.xcodeproj/project.pbxproj:
* wtf/AggregateLogger.h: Added.
(WTF::AggregateLogger::create):
(WTF::AggregateLogger::addLogger):
(WTF::AggregateLogger::removeLogger):
(WTF::AggregateLogger::logAlways const):
(WTF::AggregateLogger::error const):
(WTF::AggregateLogger::warning const):
(WTF::AggregateLogger::info const):
(WTF::AggregateLogger::debug const):
(WTF::AggregateLogger::willLog const):
(WTF::AggregateLogger::AggregateLogger):
(WTF::AggregateLogger::log const):
* wtf/CMakeLists.h:
* wtf/Logger.cpp:
(WTF::>::toString):
* wtf/Logger.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242901 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/AggregateLogger.h [new file with mode: 0644]
Source/WTF/wtf/CMakeLists.txt
Source/WTF/wtf/Logger.cpp
Source/WTF/wtf/Logger.h
Source/WebCore/ChangeLog
Source/WebCore/platform/audio/PlatformMediaSession.h
Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp
Source/WebCore/platform/audio/PlatformMediaSessionManager.h
Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h
Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm
Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h
Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm

index 2c77e0e..aed2278 100644 (file)
@@ -1,3 +1,32 @@
+2019-03-13  Jer Noble  <jer.noble@apple.com>
+
+        Add AggregateLogger, a Logger specialization for singleton classes.
+        https://bugs.webkit.org/show_bug.cgi?id=195644
+
+        Reviewed by Eric Carlson.
+
+        Add a new class, AggregateLogger, which will log messages to each of its aggregated loggers.
+
+        Drive-by fixes: allow "const void*" to be directly logged by converting the pointer to a hex string.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/AggregateLogger.h: Added.
+        (WTF::AggregateLogger::create):
+        (WTF::AggregateLogger::addLogger):
+        (WTF::AggregateLogger::removeLogger):
+        (WTF::AggregateLogger::logAlways const):
+        (WTF::AggregateLogger::error const):
+        (WTF::AggregateLogger::warning const):
+        (WTF::AggregateLogger::info const):
+        (WTF::AggregateLogger::debug const):
+        (WTF::AggregateLogger::willLog const):
+        (WTF::AggregateLogger::AggregateLogger):
+        (WTF::AggregateLogger::log const):
+        * wtf/CMakeLists.h:
+        * wtf/Logger.cpp:
+        (WTF::>::toString):
+        * wtf/Logger.h:
+
 2019-03-12  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r242747.
index 4909afa..7490fde 100644 (file)
                CD5497AB15857D0300B5BC30 /* MediaTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaTime.h; sourceTree = "<group>"; };
                CD6D9FCD1EEF3AD4008B0671 /* Algorithms.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Algorithms.h; sourceTree = "<group>"; };
                CD7600FF1F90A3CA00026E26 /* UnsafePointer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UnsafePointer.h; sourceTree = "<group>"; };
+               CDCC9BC422382FCE00FFB51C /* AggregateLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AggregateLogger.h; path = wtf/AggregateLogger.h; sourceTree = SOURCE_ROOT; };
                CE73E02419DCB7AB00580D5C /* XPCSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XPCSPI.h; sourceTree = "<group>"; };
                DCEE21FA1CEA7538000C2396 /* CFBundleSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFBundleSPI.h; sourceTree = "<group>"; };
                DCEE21FC1CEA7551000C2396 /* BlockObjCExceptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockObjCExceptions.h; sourceTree = "<group>"; };
                                A8A4731B151A825B004123FF /* text */,
                                A8A47339151A825B004123FF /* threads */,
                                A8A47348151A825B004123FF /* unicode */,
+                               CDCC9BC422382FCE00FFB51C /* AggregateLogger.h */,
                                CD6D9FCD1EEF3AD4008B0671 /* Algorithms.h */,
                                4427C5A921F6D6C300A612A4 /* ASCIICType.cpp */,
                                A8A4725A151A825A004123FF /* ASCIICType.h */,
diff --git a/Source/WTF/wtf/AggregateLogger.h b/Source/WTF/wtf/AggregateLogger.h
new file mode 100644 (file)
index 0000000..0c4dac0
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2019 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. AND ITS CONTRIBUTORS ``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 ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/Algorithms.h>
+#include <wtf/Logger.h>
+
+namespace WTF {
+
+class AggregateLogger : public Logger {
+    WTF_MAKE_NONCOPYABLE(AggregateLogger);
+public:
+
+    static Ref<AggregateLogger> create(const void* owner)
+    {
+        return adoptRef(*new AggregateLogger(owner));
+    }
+
+    void addLogger(const Logger& logger)
+    {
+        m_loggers.add(&logger);
+    }
+
+    void removeLogger(const Logger& logger)
+    {
+        m_loggers.remove(&logger);
+    }
+
+    template<typename... Arguments>
+    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
+        //  on some systems, so don't allow it.
+        UNUSED_PARAM(channel);
+#else
+        log(channel, WTFLogLevelAlways, arguments...);
+#endif
+    }
+
+    template<typename... Arguments>
+    inline void error(WTFLogChannel& channel, const Arguments&... arguments) const
+    {
+        log(channel, WTFLogLevelError, arguments...);
+    }
+
+    template<typename... Arguments>
+    inline void warning(WTFLogChannel& channel, const Arguments&... arguments) const
+    {
+        log(channel, WTFLogLevelWarning, arguments...);
+    }
+
+    template<typename... Arguments>
+    inline void info(WTFLogChannel& channel, const Arguments&... arguments) const
+    {
+        log(channel, WTFLogLevelInfo, arguments...);
+    }
+
+    template<typename... Arguments>
+    inline void debug(WTFLogChannel& channel, const Arguments&... arguments) const
+    {
+        log(channel, WTFLogLevelDebug, arguments...);
+    }
+
+    inline bool willLog(const WTFLogChannel& channel, WTFLogLevel level) const
+    {
+        return allOf(m_loggers, [channel, level] (auto& logger) { return logger->willLog(channel, level); });
+    }
+
+private:
+    AggregateLogger(const void* owner)
+        : Logger(owner)
+    {
+    }
+
+    template<typename... Argument>
+    inline void log(WTFLogChannel& channel, WTFLogLevel level, const Argument&... arguments) const
+    {
+        if (!willLog(channel, level))
+            return;
+
+        Logger::log(channel, level, arguments...);
+
+        for (auto logger : m_loggers) {
+            for (Observer& observer : logger->observers())
+                observer.didLogMessage(channel, level, { ConsoleLogValue<Argument>::toValue(arguments)... });
+        }
+    }
+
+    HashSet<RefPtr<const Logger>> m_loggers;
+};
+
+} // namespace WTF
+
+using WTF::AggregateLogger;
index 4e1f878..06ad527 100644 (file)
@@ -1,5 +1,6 @@
 set(WTF_PUBLIC_HEADERS
     ASCIICType.h
+    AggregateLogger.h
     Algorithms.h
     Assertions.h
     Atomics.h
index 6c9b0ab..b1424b7 100644 (file)
@@ -27,6 +27,7 @@
 #include "Logger.h"
 
 #include <wtf/HexNumber.h>
+#include <wtf/text/WTFString.h>
 
 namespace WTF {
 
@@ -45,6 +46,15 @@ String Logger::LogSiteIdentifier::toString() const
     return builder.toString();
 }
 
+String LogArgument<const void*>::toString(const void* argument)
+{
+    StringBuilder builder;
+    builder.append('(');
+    appendUnsignedAsHex(reinterpret_cast<uintptr_t>(argument), builder);
+    builder.append(')');
+    return builder.toString();
+}
+
 } // namespace WTF
 
 using WTF::Logger;
index 598add1..8bd993d 100644 (file)
@@ -223,6 +223,8 @@ public:
     }
 
 private:
+    friend class AggregateLogger;
+
     Logger(const void* owner)
         : m_owner { owner }
     {
@@ -259,6 +261,9 @@ private:
 template<> struct LogArgument<Logger::LogSiteIdentifier> {
     static String toString(const Logger::LogSiteIdentifier& value) { return value.toString(); }
 };
+template<> struct LogArgument<const void*> {
+    WTF_EXPORT static String toString(const void*);
+};
 
 } // namespace WTF
 
index af7dc18..7ae25ca 100644 (file)
@@ -1,3 +1,40 @@
+2019-03-13  Jer Noble  <jer.noble@apple.com>
+
+        Add AggregateLogger, a Logger specialization for singleton classes.
+        https://bugs.webkit.org/show_bug.cgi?id=195644
+
+        Reviewed by Eric Carlson.
+
+        Convert debug logging over to release logging through the use of AggregateLogger.
+
+        * platform/audio/PlatformMediaSession.h:
+        (WebCore::PlatformMediaSession::client const):
+        * platform/audio/PlatformMediaSessionManager.cpp:
+        (WebCore::PlatformMediaSessionManager::PlatformMediaSessionManager):
+        (WebCore::PlatformMediaSessionManager::beginInterruption):
+        (WebCore::PlatformMediaSessionManager::endInterruption):
+        (WebCore::PlatformMediaSessionManager::addSession):
+        (WebCore::PlatformMediaSessionManager::removeSession):
+        (WebCore::PlatformMediaSessionManager::sessionWillBeginPlayback):
+        (WebCore::PlatformMediaSessionManager::sessionWillEndPlayback):
+        (WebCore::PlatformMediaSessionManager::setCurrentSession):
+        (WebCore::PlatformMediaSessionManager::applicationWillBecomeInactive const):
+        (WebCore::PlatformMediaSessionManager::applicationDidBecomeActive const):
+        (WebCore::PlatformMediaSessionManager::applicationDidEnterBackground const):
+        (WebCore::PlatformMediaSessionManager::applicationWillEnterForeground const):
+        (WebCore::PlatformMediaSessionManager::logChannel const):
+        * platform/audio/PlatformMediaSessionManager.h:
+        * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+        (MediaSessionManagerCocoa::updateSessionState):
+        (MediaSessionManagerCocoa::sessionWillBeginPlayback):
+        (MediaSessionManagerCocoa::removeSession):
+        (MediaSessionManagerCocoa::sessionWillEndPlayback):
+        (MediaSessionManagerCocoa::clientCharacteristicsChanged):
+        (MediaSessionManagerCocoa::updateNowPlayingInfo):
+        * platform/audio/ios/MediaSessionManagerIOS.mm:
+        (WebCore::MediaSessionManageriOS::resetRestrictions):
+        (WebCore::MediaSessionManageriOS::configureWireLessTargetMonitoring):
+
 2019-03-13  Chris Dumez  <cdumez@apple.com>
 
         Drop legacy WebCore::toRegistrableDomain() utility function
index 87e192f..b5d792f 100644 (file)
@@ -182,9 +182,6 @@ public:
     bool hasPlayedSinceLastInterruption() const { return m_hasPlayedSinceLastInterruption; }
     void clearHasPlayedSinceLastInterruption() { m_hasPlayedSinceLastInterruption = false; }
 
-protected:
-    PlatformMediaSessionClient& client() const { return m_client; }
-
 #if !RELEASE_LOG_DISABLED
     const Logger& logger() const final { return m_logger.get(); }
     const void* logIdentifier() const override { return reinterpret_cast<const void*>(m_logIdentifier); }
@@ -192,6 +189,9 @@ protected:
     WTFLogChannel& logChannel() const final;
 #endif
 
+protected:
+    PlatformMediaSessionClient& client() const { return m_client; }
+
 private:
     PlatformMediaSessionClient& m_client;
     State m_state;
index b9b079d..71140ba 100644 (file)
@@ -59,6 +59,9 @@ void PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary()
 
 PlatformMediaSessionManager::PlatformMediaSessionManager()
     : m_systemSleepListener(PAL::SystemSleepListener::create(*this))
+#if !RELEASE_LOG_DISABLED
+    , m_logger(AggregateLogger::create(this))
+#endif
 {
     resetRestrictions();
 }
@@ -110,7 +113,7 @@ int PlatformMediaSessionManager::count(PlatformMediaSession::MediaType type) con
 
 void PlatformMediaSessionManager::beginInterruption(PlatformMediaSession::InterruptionType type)
 {
-    LOG(Media, "PlatformMediaSessionManager::beginInterruption");
+    ALWAYS_LOG(LOGIDENTIFIER);
 
     m_interrupted = true;
     forEachSession([type] (PlatformMediaSession& session, size_t) {
@@ -121,7 +124,7 @@ void PlatformMediaSessionManager::beginInterruption(PlatformMediaSession::Interr
 
 void PlatformMediaSessionManager::endInterruption(PlatformMediaSession::EndInterruptionFlags flags)
 {
-    LOG(Media, "PlatformMediaSessionManager::endInterruption");
+    ALWAYS_LOG(LOGIDENTIFIER);
 
     m_interrupted = false;
     forEachSession([flags] (PlatformMediaSession& session, size_t) {
@@ -131,7 +134,7 @@ void PlatformMediaSessionManager::endInterruption(PlatformMediaSession::EndInter
 
 void PlatformMediaSessionManager::addSession(PlatformMediaSession& session)
 {
-    LOG(Media, "PlatformMediaSessionManager::addSession - %p", &session);
+    ALWAYS_LOG(LOGIDENTIFIER, session.logIdentifier());
     
     m_sessions.append(&session);
     if (m_interrupted)
@@ -143,12 +146,16 @@ void PlatformMediaSessionManager::addSession(PlatformMediaSession& session)
     if (!m_audioHardwareListener)
         m_audioHardwareListener = AudioHardwareListener::create(*this);
 
+#if !RELEASE_LOG_DISABLED
+    m_logger->addLogger(session.logger());
+#endif
+
     updateSessionState();
 }
 
 void PlatformMediaSessionManager::removeSession(PlatformMediaSession& session)
 {
-    LOG(Media, "PlatformMediaSessionManager::removeSession - %p", &session);
+    ALWAYS_LOG(LOGIDENTIFIER, session.logIdentifier());
     
     size_t index = m_sessions.find(&session);
     if (index == notFound)
@@ -170,6 +177,10 @@ void PlatformMediaSessionManager::removeSession(PlatformMediaSession& session)
 #endif
     }
 
+#if !RELEASE_LOG_DISABLED
+    m_logger->removeLogger(session.logger());
+#endif
+
     updateSessionState();
 }
 
@@ -193,7 +204,7 @@ PlatformMediaSessionManager::SessionRestrictions PlatformMediaSessionManager::re
 
 bool PlatformMediaSessionManager::sessionWillBeginPlayback(PlatformMediaSession& session)
 {
-    LOG(Media, "PlatformMediaSessionManager::sessionWillBeginPlayback - %p", &session);
+    ALWAYS_LOG(LOGIDENTIFIER, session.logIdentifier());
     
     setCurrentSession(session);
 
@@ -226,7 +237,7 @@ bool PlatformMediaSessionManager::sessionWillBeginPlayback(PlatformMediaSession&
     
 void PlatformMediaSessionManager::sessionWillEndPlayback(PlatformMediaSession& session)
 {
-    LOG(Media, "PlatformMediaSessionManager::sessionWillEndPlayback - %p", &session);
+    ALWAYS_LOG(LOGIDENTIFIER, session.logIdentifier());
     
     if (m_sessions.size() < 2)
         return;
@@ -253,7 +264,7 @@ void PlatformMediaSessionManager::sessionWillEndPlayback(PlatformMediaSession& s
     m_sessions.remove(pausingSessionIndex);
     m_sessions.insert(lastPlayingSessionIndex, &session);
     
-    LOG(Media, "PlatformMediaSessionManager::sessionWillEndPlayback - session moved from index %zu to %zu", pausingSessionIndex, lastPlayingSessionIndex);
+    ALWAYS_LOG(LOGIDENTIFIER, "session moved from index ", pausingSessionIndex, " to ", lastPlayingSessionIndex);
 }
 
 void PlatformMediaSessionManager::sessionStateChanged(PlatformMediaSession&)
@@ -263,7 +274,7 @@ void PlatformMediaSessionManager::sessionStateChanged(PlatformMediaSession&)
 
 void PlatformMediaSessionManager::setCurrentSession(PlatformMediaSession& session)
 {
-    LOG(Media, "PlatformMediaSessionManager::setCurrentSession - %p", &session);
+    ALWAYS_LOG(LOGIDENTIFIER, session.logIdentifier());
     
     if (m_sessions.size() < 2)
         return;
@@ -278,7 +289,7 @@ void PlatformMediaSessionManager::setCurrentSession(PlatformMediaSession& sessio
     if (m_remoteCommandListener)
         m_remoteCommandListener->updateSupportedCommands();
     
-    LOG(Media, "PlatformMediaSessionManager::setCurrentSession - session moved from index %zu to 0", index);
+    ALWAYS_LOG(LOGIDENTIFIER, "session moved from index ", index, " to 0");
 }
     
 PlatformMediaSession* PlatformMediaSessionManager::currentSession() const
@@ -301,7 +312,7 @@ Vector<PlatformMediaSession*> PlatformMediaSessionManager::currentSessionsMatchi
 
 void PlatformMediaSessionManager::applicationWillBecomeInactive() const
 {
-    LOG(Media, "PlatformMediaSessionManager::applicationWillBecomeInactive");
+    ALWAYS_LOG(LOGIDENTIFIER);
 
     forEachSession([&] (PlatformMediaSession& session, size_t) {
         if (m_restrictions[session.mediaType()] & InactiveProcessPlaybackRestricted)
@@ -311,7 +322,7 @@ void PlatformMediaSessionManager::applicationWillBecomeInactive() const
 
 void PlatformMediaSessionManager::applicationDidBecomeActive() const
 {
-    LOG(Media, "PlatformMediaSessionManager::applicationDidBecomeActive");
+    ALWAYS_LOG(LOGIDENTIFIER);
 
     forEachSession([&] (PlatformMediaSession& session, size_t) {
         if (m_restrictions[session.mediaType()] & InactiveProcessPlaybackRestricted)
@@ -321,7 +332,7 @@ void PlatformMediaSessionManager::applicationDidBecomeActive() const
 
 void PlatformMediaSessionManager::applicationDidEnterBackground(bool suspendedUnderLock) const
 {
-    LOG(Media, "PlatformMediaSessionManager::applicationDidEnterBackground - suspendedUnderLock(%d)", suspendedUnderLock);
+    ALWAYS_LOG(LOGIDENTIFIER, "suspendedUnderLock: ", suspendedUnderLock);
 
     if (m_isApplicationInBackground)
         return;
@@ -338,7 +349,7 @@ void PlatformMediaSessionManager::applicationDidEnterBackground(bool suspendedUn
 
 void PlatformMediaSessionManager::applicationWillEnterForeground(bool suspendedUnderLock) const
 {
-    LOG(Media, "PlatformMediaSessionManager::applicationWillEnterForeground - suspendedUnderLock(%d)", suspendedUnderLock);
+    ALWAYS_LOG(LOGIDENTIFIER, "suspendedUnderLock: ", suspendedUnderLock);
 
     if (!m_isApplicationInBackground)
         return;
@@ -518,4 +529,11 @@ void PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary()
 
 #endif // ENABLE(VIDEO) || ENABLE(WEB_AUDIO)
 
+#if !RELEASE_LOG_DISABLED
+WTFLogChannel& PlatformMediaSessionManager::logChannel() const
+{
+    return LogMedia;
+}
+#endif
+
 } // namespace WebCore
index b795ff2..135a8d1 100644 (file)
@@ -31,6 +31,7 @@
 #include "RemoteCommandListener.h"
 #include "Timer.h"
 #include <pal/system/SystemSleepListener.h>
+#include <wtf/AggregateLogger.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -40,7 +41,14 @@ class HTMLMediaElement;
 class PlatformMediaSession;
 class RemoteCommandListener;
 
-class PlatformMediaSessionManager : private RemoteCommandListenerClient, private PAL::SystemSleepListener::Client, private AudioHardwareListener::Client {
+class PlatformMediaSessionManager
+    : private RemoteCommandListenerClient
+    , private PAL::SystemSleepListener::Client
+    , private AudioHardwareListener::Client
+#if !RELEASE_LOG_DISABLED
+    , private LoggerHelper
+#endif
+{
     WTF_MAKE_FAST_ALLOCATED;
 public:
     WEBCORE_EXPORT static PlatformMediaSessionManager* sharedManagerIfExists();
@@ -133,6 +141,13 @@ protected:
 
     AudioHardwareListener* audioHardwareListener() { return m_audioHardwareListener.get(); }
 
+#if !RELEASE_LOG_DISABLED
+    const Logger& logger() const final { return m_logger; }
+    const void* logIdentifier() const final { return nullptr; }
+    const char* logClassName() const override { return "PlatformMediaSessionManager"; }
+    WTFLogChannel& logChannel() const final;
+#endif
+
 private:
     friend class Internals;
 
@@ -172,6 +187,10 @@ private:
 #if USE(AUDIO_SESSION)
     bool m_becameActive { false };
 #endif
+
+#if !RELEASE_LOG_DISABLED
+    Ref<AggregateLogger> m_logger;
+#endif
 };
 
 }
index 7fffb8a..e68571c 100644 (file)
@@ -63,6 +63,10 @@ protected:
     PlatformMediaSession* nowPlayingEligibleSession();
 
 private:
+#if !RELEASE_LOG_DISABLED
+    const char* logClassName() const override { return "MediaSessionManagerCocoa"; }
+#endif
+
     bool m_nowPlayingActive { false };
     bool m_registeredAsNowPlayingApplication { false };
 
index 68b0c39..3d4194b 100644 (file)
@@ -62,7 +62,11 @@ PlatformMediaSessionManager* PlatformMediaSessionManager::sharedManagerIfExists(
 
 void MediaSessionManagerCocoa::updateSessionState()
 {
-    LOG(Media, "PlatformMediaSessionManager::scheduleUpdateSessionState() - types: Video(%d), Audio(%d), WebAudio(%d)", count(PlatformMediaSession::Video), count(PlatformMediaSession::Audio), count(PlatformMediaSession::WebAudio));
+    ALWAYS_LOG(LOGIDENTIFIER, "types: "
+        "Video(", count(PlatformMediaSession::Video), "), "
+        "Audio(", count(PlatformMediaSession::Audio), "), "
+        "VideoAudio(", count(PlatformMediaSession::VideoAudio), "), "
+        "WebAudio(", count(PlatformMediaSession::WebAudio), ")");
 
     if (has(PlatformMediaSession::WebAudio))
         AudioSession::sharedSession().setPreferredBufferSize(kWebAudioBufferSize);
@@ -136,7 +140,6 @@ bool MediaSessionManagerCocoa::sessionWillBeginPlayback(PlatformMediaSession& se
     if (!PlatformMediaSessionManager::sessionWillBeginPlayback(session))
         return false;
     
-    LOG(Media, "MediaSessionManagerCocoa::sessionWillBeginPlayback");
     scheduleUpdateNowPlayingInfo();
     return true;
 }
@@ -149,20 +152,18 @@ void MediaSessionManagerCocoa::sessionDidEndRemoteScrubbing(const PlatformMediaS
 void MediaSessionManagerCocoa::removeSession(PlatformMediaSession& session)
 {
     PlatformMediaSessionManager::removeSession(session);
-    LOG(Media, "MediaSessionManagerCocoa::removeSession");
     scheduleUpdateNowPlayingInfo();
 }
 
 void MediaSessionManagerCocoa::sessionWillEndPlayback(PlatformMediaSession& session)
 {
     PlatformMediaSessionManager::sessionWillEndPlayback(session);
-    LOG(Media, "MediaSessionManagerCocoa::sessionWillEndPlayback");
     updateNowPlayingInfo();
 }
 
-void MediaSessionManagerCocoa::clientCharacteristicsChanged(PlatformMediaSession&)
+void MediaSessionManagerCocoa::clientCharacteristicsChanged(PlatformMediaSession& session)
 {
-    LOG(Media, "MediaSessionManagerCocoa::clientCharacteristicsChanged");
+    ALWAYS_LOG(LOGIDENTIFIER, session.logIdentifier());
     scheduleUpdateNowPlayingInfo();
 }
 
@@ -190,13 +191,13 @@ void MediaSessionManagerCocoa::updateNowPlayingInfo()
 
     const PlatformMediaSession* currentSession = this->nowPlayingEligibleSession();
 
-    LOG(Media, "MediaSessionManagerCocoa::updateNowPlayingInfo - currentSession = %p", currentSession);
+    ALWAYS_LOG(LOGIDENTIFIER, "currentSession: ", currentSession ? currentSession->logIdentifier() : nullptr);
 
     if (!currentSession) {
         if (canLoad_MediaRemote_MRMediaRemoteSetNowPlayingVisibility())
             MRMediaRemoteSetNowPlayingVisibility(MRMediaRemoteGetLocalOrigin(), MRNowPlayingClientVisibilityNeverVisible);
 
-        LOG(Media, "MediaSessionManagerCocoa::updateNowPlayingInfo - clearing now playing info");
+        ALWAYS_LOG(LOGIDENTIFIER, "clearing now playing info");
 
         MRMediaRemoteSetCanBeNowPlayingApplication(false);
         m_registeredAsNowPlayingApplication = false;
@@ -212,7 +213,7 @@ void MediaSessionManagerCocoa::updateNowPlayingInfo()
             UNUSED_PARAM(error);
 #else
             if (error)
-                LOG(Media, "MediaSessionManagerCocoa::updateNowPlayingInfo - MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(stopped) failed with error %ud", error);
+                ALWAYS_LOG(LOGIDENTIFIER, "MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(stopped) failed with error ", error);
 #endif
         });
 
@@ -255,8 +256,7 @@ void MediaSessionManagerCocoa::updateNowPlayingInfo()
         m_lastUpdatedNowPlayingElapsedTime = currentTime;
     }
 
-    LOG(Media, "MediaSessionManagerCocoa::updateNowPlayingInfo - title = \"%s\", rate = %f, duration = %f, now = %f",
-        title.utf8().data(), rate, duration, currentTime);
+    ALWAYS_LOG(LOGIDENTIFIER, "title = \"", title, "\", rate = ", rate, ", duration = ", duration, ", now = ", currentTime);
 
     String parentApplication = currentSession->sourceApplicationIdentifier();
     if (canLoad_MediaRemote_MRMediaRemoteSetParentApplication() && !parentApplication.isEmpty())
@@ -268,7 +268,7 @@ void MediaSessionManagerCocoa::updateNowPlayingInfo()
 #if LOG_DISABLED
         UNUSED_PARAM(error);
 #else
-        LOG(Media, "MediaSessionManagerCocoa::updateNowPlayingInfo - MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(playing) failed with error %ud", error);
+        ALWAYS_LOG(LOGIDENTIFIER, "MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(playing) failed with error ", error);
 #endif
     });
     MRMediaRemoteSetNowPlayingInfo(info.get());
index df02792..eb01d6f 100644 (file)
@@ -58,6 +58,10 @@ private:
     void configureWireLessTargetMonitoring() override;
     void providePresentingApplicationPIDIfNecessary() final;
 
+#if !RELEASE_LOG_DISABLED
+    const char* logClassName() const final { return "MediaSessionManageriOS"; }
+#endif
+
     RetainPtr<WebMediaSessionHelper> m_objcObserver;
 #if HAVE(CELESTIAL)
     bool m_havePresentedApplicationPID { false };
index c1f1c48..d62593a 100644 (file)
@@ -137,12 +137,12 @@ void MediaSessionManageriOS::resetRestrictions()
 {
     static const size_t systemMemoryRequiredForVideoInBackgroundTabs = 1024 * 1024 * 1024;
 
-    LOG(Media, "MediaSessionManageriOS::resetRestrictions");
+    ALWAYS_LOG(LOGIDENTIFIER);
 
     PlatformMediaSessionManager::resetRestrictions();
 
     if (ramSize() < systemMemoryRequiredForVideoInBackgroundTabs) {
-        LOG(Media, "MediaSessionManageriOS::resetRestrictions - restricting video in background tabs because system memory = %zul", ramSize());
+        ALWAYS_LOG(LOGIDENTIFIER, "restricting video in background tabs because system memory = ", ramSize());
         addRestriction(PlatformMediaSession::Video, BackgroundTabPlaybackRestricted);
     }
 
@@ -164,7 +164,7 @@ void MediaSessionManageriOS::configureWireLessTargetMonitoring()
         return session.requiresPlaybackTargetRouteMonitoring();
     });
 
-    LOG(Media, "MediaSessionManageriOS::configureWireLessTargetMonitoring - requiresMonitoring = %s", requiresMonitoring ? "true" : "false");
+    ALWAYS_LOG(LOGIDENTIFIER, "requiresMonitoring = ", requiresMonitoring);
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS