IVGCVSW-6843 replace armnn::Logging with arm::pipe::Logging in profiling code

Change-Id: I9c3af46ca02c5685e06657b8af0e4658d71891d4
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
diff --git a/Android.mk b/Android.mk
index 5c722e1..29ca965 100644
--- a/Android.mk
+++ b/Android.mk
@@ -110,6 +110,7 @@
         profiling/common/src/CommandHandlerKey.cpp \
         profiling/common/src/CommandHandlerRegistry.cpp \
         profiling/common/src/CommonProfilingUtils.cpp \
+        profiling/common/src/Logging.cpp \
         profiling/common/src/NetworkSockets.cpp \
         profiling/common/src/PacketVersionResolver.cpp \
         profiling/common/src/SwTrace.cpp \
diff --git a/profiling/common/include/Logging.hpp b/profiling/common/include/Logging.hpp
index a31c2aa..7a265d5 100644
--- a/profiling/common/include/Logging.hpp
+++ b/profiling/common/include/Logging.hpp
@@ -16,6 +16,14 @@
 namespace pipe
 {
 
+#if defined(__clang__) &&((__clang_major__>=3)||(__clang_major__==3 && __clang_minor__ >= 5))
+#   define ARM_PIPE_FALLTHROUGH [[clang::fallthrough]]
+#elif defined(__GNUC__) && (__GNUC__ >= 7)
+#   define ARM_PIPE_FALLTHROUGH __attribute__((fallthrough))
+#else
+#   define ARM_PIPE_FALLTHROUGH ((void)0)
+#endif
+
 enum class LogSeverity
 {
     Trace,
@@ -47,6 +55,13 @@
     }
 }
 
+/// Configures the logging behaviour of the ARMNN library.
+///     printToStandardOutput: Set to true if log messages should be printed to the standard output.
+///     printToDebugOutput: Set to true if log messages be printed to a platform-specific debug output
+///       (where supported).
+///     severity: All log messages that are at this severity level or higher will be printed, others will be ignored.
+void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity);
+
 class LogSink
 {
 public:
@@ -124,7 +139,7 @@
     {
     }
 
-    static SimpleLogger& Get()
+    static SimpleLogger<Level>& Get()
     {
         static SimpleLogger<Level> logger;
         return logger;
diff --git a/profiling/common/src/CMakeLists.txt b/profiling/common/src/CMakeLists.txt
index b4dc59f..1b47b6c 100644
--- a/profiling/common/src/CMakeLists.txt
+++ b/profiling/common/src/CMakeLists.txt
@@ -10,6 +10,7 @@
         CommandHandlerKey.cpp
         CommandHandlerRegistry.cpp
         CommonProfilingUtils.cpp
+        Logging.cpp
         NetworkSockets.cpp
         PacketVersionResolver.cpp
         SwTrace.cpp
diff --git a/profiling/common/src/Logging.cpp b/profiling/common/src/Logging.cpp
new file mode 100644
index 0000000..72f6aec
--- /dev/null
+++ b/profiling/common/src/Logging.cpp
@@ -0,0 +1,204 @@
+//
+// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <common/include/Logging.hpp>
+#include <common/include/IgnoreUnused.hpp>
+#include <common/include/Assert.hpp>
+
+#if defined(_MSC_VER)
+#include <common/include/WindowsWrapper.hpp>
+#endif
+
+#if defined(__ANDROID__)
+#include <android/log.h>
+#endif
+
+#include <iostream>
+
+namespace arm
+{
+
+namespace pipe
+{
+
+template<>
+SimpleLogger<LogSeverity::Debug>& SimpleLogger<LogSeverity::Debug>::Get()
+{
+    static SimpleLogger<LogSeverity::Debug> logger;
+    return logger;
+}
+
+template<>
+SimpleLogger<LogSeverity::Trace>& SimpleLogger<LogSeverity::Trace>::Get()
+{
+    static SimpleLogger<LogSeverity::Trace> logger;
+    return logger;
+}
+
+template<>
+SimpleLogger<LogSeverity::Info>& SimpleLogger<LogSeverity::Info>::Get()
+{
+    static SimpleLogger<LogSeverity::Info> logger;
+    return logger;
+}
+
+template<>
+SimpleLogger<LogSeverity::Warning>& SimpleLogger<LogSeverity::Warning>::Get()
+{
+    static SimpleLogger<LogSeverity::Warning> logger;
+    return logger;
+}
+
+template<>
+SimpleLogger<LogSeverity::Error>& SimpleLogger<LogSeverity::Error>::Get()
+{
+    static SimpleLogger<LogSeverity::Error> logger;
+    return logger;
+}
+
+template<>
+SimpleLogger<LogSeverity::Fatal>& SimpleLogger<LogSeverity::Fatal>::Get()
+{
+    static SimpleLogger<LogSeverity::Fatal> logger;
+    return logger;
+}
+
+void SetLogFilter(LogSeverity level)
+{
+    SimpleLogger<LogSeverity::Trace>::Get().Enable(false);
+    SimpleLogger<LogSeverity::Debug>::Get().Enable(false);
+    SimpleLogger<LogSeverity::Info>::Get().Enable(false);
+    SimpleLogger<LogSeverity::Warning>::Get().Enable(false);
+    SimpleLogger<LogSeverity::Error>::Get().Enable(false);
+    SimpleLogger<LogSeverity::Fatal>::Get().Enable(false);
+    switch (level)
+    {
+        case LogSeverity::Trace:
+            SimpleLogger<LogSeverity::Trace>::Get().Enable(true);
+            ARM_PIPE_FALLTHROUGH;
+        case LogSeverity::Debug:
+            SimpleLogger<LogSeverity::Debug>::Get().Enable(true);
+            ARM_PIPE_FALLTHROUGH;
+        case LogSeverity::Info:
+            SimpleLogger<LogSeverity::Info>::Get().Enable(true);
+            ARM_PIPE_FALLTHROUGH;
+        case LogSeverity::Warning:
+            SimpleLogger<LogSeverity::Warning>::Get().Enable(true);
+            ARM_PIPE_FALLTHROUGH;
+        case LogSeverity::Error:
+            SimpleLogger<LogSeverity::Error>::Get().Enable(true);
+            ARM_PIPE_FALLTHROUGH;
+        case LogSeverity::Fatal:
+            SimpleLogger<LogSeverity::Fatal>::Get().Enable(true);
+            break;
+        default:
+            ARM_PIPE_ASSERT(false);
+    }
+}
+
+class StandardOutputColourSink : public LogSink
+{
+public:
+    StandardOutputColourSink(LogSeverity level = LogSeverity::Info)
+    : m_Level(level)
+    {
+    }
+
+    void Consume(const std::string& s) override
+    {
+        std::cout << GetColour(m_Level) << s << ResetColour() << std::endl;
+    }
+
+private:
+    std::string ResetColour()
+    {
+        return "\033[0m";
+    }
+
+    std::string GetColour(LogSeverity level)
+    {
+        switch(level)
+        {
+            case LogSeverity::Trace:
+                return "\033[35m";
+            case LogSeverity::Debug:
+                return "\033[32m";
+            case LogSeverity::Info:
+                return "\033[0m";
+            case LogSeverity::Warning:
+                return "\033[33m";
+            case LogSeverity::Error:
+                return "\033[31m";
+            case LogSeverity::Fatal:
+                return "\033[41;30m";
+
+            default:
+                return "\033[0m";
+        }
+    }
+    LogSeverity m_Level;
+};
+
+class DebugOutputSink : public LogSink
+{
+public:
+    void Consume(const std::string& s) override
+    {
+        IgnoreUnused(s);
+#if defined(_MSC_VER)
+        OutputDebugString(s.c_str());
+        OutputDebugString("\n");
+#elif defined(__ANDROID__)
+        __android_log_write(ANDROID_LOG_DEBUG, "armnn", s.c_str());
+#else
+        IgnoreUnused(s);
+#endif
+    }
+};
+
+template<LogSeverity Level>
+inline void SetLoggingSinks(bool standardOut, bool debugOut, bool coloured)
+{
+    SimpleLogger<Level>::Get().RemoveAllSinks();
+
+    if (standardOut)
+    {
+        if (coloured)
+        {
+            SimpleLogger<Level>::Get().AddSink(
+                std::make_shared<StandardOutputColourSink>(Level));
+        } else
+        {
+            SimpleLogger<Level>::Get().AddSink(
+                std::make_shared<StandardOutputSink>());
+        }
+    }
+
+    if (debugOut)
+    {
+        SimpleLogger<Level>::Get().AddSink(
+            std::make_shared<DebugOutputSink>());
+    }
+}
+
+void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured)
+{
+    SetLoggingSinks<LogSeverity::Trace>(standardOut, debugOut, coloured);
+    SetLoggingSinks<LogSeverity::Debug>(standardOut, debugOut, coloured);
+    SetLoggingSinks<LogSeverity::Info>(standardOut, debugOut, coloured);
+    SetLoggingSinks<LogSeverity::Warning>(standardOut, debugOut, coloured);
+    SetLoggingSinks<LogSeverity::Error>(standardOut, debugOut, coloured);
+    SetLoggingSinks<LogSeverity::Fatal>(standardOut, debugOut, coloured);
+}
+
+void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity)
+{
+    SetAllLoggingSinks(printToStandardOutput, printToDebugOutput, false);
+    SetLogFilter(severity);
+}
+
+} // namespace pipe
+
+} // namespace armnn
diff --git a/src/armnn/test/RuntimeTests.cpp b/src/armnn/test/RuntimeTests.cpp
index 9cf322c..89a8719 100644
--- a/src/armnn/test/RuntimeTests.cpp
+++ b/src/armnn/test/RuntimeTests.cpp
@@ -13,7 +13,6 @@
 #include <Runtime.hpp>
 #include <armnn/TypesUtils.hpp>
 
-
 #include <common/include/LabelsAndEventClasses.hpp>
 #include <test/ProfilingTestUtils.hpp>
 
@@ -36,7 +35,7 @@
     runtime->m_LoadedNetworks.reserve(1);
 }
 
-}
+} // namespace armnn
 
 TEST_SUITE("Runtime")
 {
@@ -600,6 +599,8 @@
 {
     using namespace armnn;
 
+    LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
+
     // Create runtime in which the test will run
     armnn::IRuntime::CreationOptions options;
     armnn::RuntimeImpl runtime(options);
diff --git a/src/backends/backendsCommon/test/BackendProfilingTests.cpp b/src/backends/backendsCommon/test/BackendProfilingTests.cpp
index f1ec46b..253ff4a 100644
--- a/src/backends/backendsCommon/test/BackendProfilingTests.cpp
+++ b/src/backends/backendsCommon/test/BackendProfilingTests.cpp
@@ -31,6 +31,32 @@
 #include <limits>
 #include <backends/BackendProfiling.hpp>
 
+
+namespace arm
+{
+
+namespace pipe
+{
+
+struct LogLevelSwapper
+{
+public:
+    LogLevelSwapper(arm::pipe::LogSeverity severity)
+    {
+        // Set the new log level
+        arm::pipe::ConfigureLogging(true, true, severity);
+    }
+    ~LogLevelSwapper()
+    {
+        // The default log level for unit tests is "Fatal"
+        arm::pipe::ConfigureLogging(true, true, arm::pipe::LogSeverity::Fatal);
+    }
+};
+
+} // namespace pipe
+
+} // namespace arm
+
 using namespace arm::pipe;
 
 class ReadCounterVals : public IReadCounterValues
@@ -123,6 +149,8 @@
 {
 TEST_CASE("BackendProfilingCounterRegisterMockBackendTest")
 {
+    arm::pipe::LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
+
     // Reset the profiling service to the uninitialized state
     armnn::IRuntime::CreationOptions options;
     options.m_ProfilingOptions.m_EnableProfiling = true;
@@ -154,6 +182,8 @@
 
 TEST_CASE("TestBackendCounters")
 {
+    arm::pipe::LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
+
     Holder holder;
     arm::pipe::PacketVersionResolver packetVersionResolver;
     ProfilingStateMachine stateMachine;
@@ -457,17 +487,19 @@
 
     uint32_t period = 15939u;
 
-    armnn::SetAllLoggingSinks(true, false, false);
-    SetLogFilter(armnn::LogSeverity::Warning);
+    arm::pipe::SetAllLoggingSinks(true, false, false);
+    arm::pipe::SetLogFilter(arm::pipe::LogSeverity::Warning);
     periodicCounterSelectionCommandHandler(PacketWriter(period, {5}));
     periodicCounterCapture.Stop();
-    SetLogFilter(armnn::LogSeverity::Fatal);
+    arm::pipe::SetLogFilter(arm::pipe::LogSeverity::Fatal);
 
     CHECK(ss.str().find("ActivateCounters example test error") != std::string::npos);
 }
 
 TEST_CASE("BackendProfilingContextGetSendTimelinePacket")
 {
+    arm::pipe::LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
+
     // Reset the profiling service to the uninitialized state
     armnn::IRuntime::CreationOptions options;
     options.m_ProfilingOptions.m_EnableProfiling = true;
@@ -507,6 +539,8 @@
 
 TEST_CASE("GetProfilingGuidGenerator")
 {
+    arm::pipe::LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
+
     // Reset the profiling service to the uninitialized state
     armnn::IRuntime::CreationOptions options;
     options.m_ProfilingOptions.m_EnableProfiling = true;
diff --git a/src/profiling/CommandHandler.cpp b/src/profiling/CommandHandler.cpp
index ff7b5a5..6ba49c2 100644
--- a/src/profiling/CommandHandler.cpp
+++ b/src/profiling/CommandHandler.cpp
@@ -6,7 +6,7 @@
 #include "CommandHandler.hpp"
 #include "ProfilingService.hpp"
 
-#include <armnn/Logging.hpp>
+#include <common/include/Logging.hpp>
 
 namespace arm
 {
@@ -75,7 +75,7 @@
         catch (const arm::pipe::ProfilingException& e)
         {
             // Log the error and continue
-            ARMNN_LOG(warning) << "An error has occurred when handling a command: " << e.what();
+            ARM_PIPE_LOG(warning) << "An error has occurred when handling a command: " << e.what();
             // Did we get here because the socket failed?
             if ( !profilingConnection.IsOpen() )
             {
@@ -88,7 +88,7 @@
         catch (...)
         {
             // Log the error and continue
-            ARMNN_LOG(warning) << "An unknown error has occurred when handling a command";
+            ARM_PIPE_LOG(warning) << "An unknown error has occurred when handling a command";
             // Did we get here because the socket failed?
             if ( !profilingConnection.IsOpen() )
             {
diff --git a/src/profiling/PeriodicCounterCapture.cpp b/src/profiling/PeriodicCounterCapture.cpp
index 650043d..490173c 100644
--- a/src/profiling/PeriodicCounterCapture.cpp
+++ b/src/profiling/PeriodicCounterCapture.cpp
@@ -5,7 +5,7 @@
 
 #include "PeriodicCounterCapture.hpp"
 
-#include <armnn/Logging.hpp>
+#include <common/include/Logging.hpp>
 
 #include <iostream>
 
@@ -108,7 +108,7 @@
                 catch (const arm::pipe::ProfilingException& e)
                 {
                     // Report the error and continue
-                    ARMNN_LOG(warning) << "An error has occurred when getting a counter value: "
+                    ARM_PIPE_LOG(warning) << "An error has occurred when getting a counter value: "
                                        << e.what();
                     continue;
                 }
diff --git a/src/profiling/PeriodicCounterSelectionCommandHandler.hpp b/src/profiling/PeriodicCounterSelectionCommandHandler.hpp
index 4d94ba1..98a8ee0 100644
--- a/src/profiling/PeriodicCounterSelectionCommandHandler.hpp
+++ b/src/profiling/PeriodicCounterSelectionCommandHandler.hpp
@@ -13,10 +13,10 @@
 #include "ICounterValues.hpp"
 
 #include "armnn/backends/profiling/IBackendProfilingContext.hpp"
-#include "armnn/Logging.hpp"
 #include "armnn/BackendRegistry.hpp"
 
 #include <common/include/CommandHandlerFunctor.hpp>
+#include <common/include/Logging.hpp>
 #include <common/include/Packet.hpp>
 
 #include <set>
@@ -86,7 +86,7 @@
 
         if(errorMsg.has_value())
         {
-            ARMNN_LOG(warning) << "An error has occurred when activating counters of " << backendId << ": "
+            ARM_PIPE_LOG(warning) << "An error has occurred when activating counters of " << backendId << ": "
                                << errorMsg.value();
         }
     }
@@ -100,4 +100,3 @@
 } // namespace pipe
 
 } // namespace arm
-
diff --git a/src/profiling/ProfilingService.cpp b/src/profiling/ProfilingService.cpp
index 677158e..b5f398d 100644
--- a/src/profiling/ProfilingService.cpp
+++ b/src/profiling/ProfilingService.cpp
@@ -5,11 +5,9 @@
 
 #include "ProfilingService.hpp"
 
-#include <armnn/Logging.hpp>
-
+#include <common/include/Logging.hpp>
 #include <common/include/NumericCast.hpp>
 #include <common/include/ProfilingGuid.hpp>
-
 #include <common/include/SocketConnectionException.hpp>
 
 #include <fmt/format.h>
@@ -131,12 +129,12 @@
         }
         catch (const arm::pipe::ProfilingException& e)
         {
-            ARMNN_LOG(warning) << "An error has occurred when creating the profiling connection: "
+            ARM_PIPE_LOG(warning) << "An error has occurred when creating the profiling connection: "
                                        << e.what();
         }
         catch (const arm::pipe::SocketConnectionException& e)
         {
-            ARMNN_LOG(warning) << "An error has occurred when creating the profiling connection ["
+            ARM_PIPE_LOG(warning) << "An error has occurred when creating the profiling connection ["
                                        << e.what() << "] on socket [" << e.GetSocketFd() << "].";
         }
 
@@ -425,7 +423,7 @@
         std::chrono::duration<double, std::milli> elapsed = finish - start;
         std::stringstream ss;
         ss << "Timed out waiting on profiling service activation for " << elapsed.count() << " ms";
-        ARMNN_LOG(warning) << ss.str();
+        ARM_PIPE_LOG(warning) << ss.str();
     }
     return;
 }
diff --git a/src/profiling/test/ProfilingTestUtils.hpp b/src/profiling/test/ProfilingTestUtils.hpp
index 323a762..32db72a 100644
--- a/src/profiling/test/ProfilingTestUtils.hpp
+++ b/src/profiling/test/ProfilingTestUtils.hpp
@@ -89,6 +89,46 @@
     }
 };
 
+struct LogLevelSwapper
+{
+public:
+    LogLevelSwapper(arm::pipe::LogSeverity severity)
+    {
+        // Set the new log level
+        arm::pipe::ConfigureLogging(true, true, severity);
+    }
+    ~LogLevelSwapper()
+    {
+        // The default log level for unit tests is "Fatal"
+        arm::pipe::ConfigureLogging(true, true, arm::pipe::LogSeverity::Fatal);
+    }
+};
+
+struct StreamRedirector
+{
+public:
+    StreamRedirector(std::ostream& stream, std::streambuf* newStreamBuffer)
+        : m_Stream(stream)
+        , m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
+    {}
+
+    ~StreamRedirector() { CancelRedirect(); }
+
+    void CancelRedirect()
+    {
+        // Only cancel the redirect once.
+        if (m_BackupBuffer != nullptr )
+        {
+            m_Stream.rdbuf(m_BackupBuffer);
+            m_BackupBuffer = nullptr;
+        }
+    }
+
+private:
+    std::ostream& m_Stream;
+    std::streambuf* m_BackupBuffer;
+};
+
 } // namespace pipe
 
 } // namespace arm
diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp
index 43938cf..9c3007b 100644
--- a/src/profiling/test/ProfilingTests.cpp
+++ b/src/profiling/test/ProfilingTests.cpp
@@ -139,6 +139,8 @@
 
 TEST_CASE("CheckCommandHandler")
 {
+    LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
+
     arm::pipe::PacketVersionResolver packetVersionResolver;
     ProfilingStateMachine profilingStateMachine;
 
@@ -3153,7 +3155,12 @@
 TEST_CASE("CheckProfilingServiceEnabled")
 {
     // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
-    LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
+    LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
+
+    // Redirect the output to a local stream so that we can parse the warning message
+    std::stringstream ss;
+    StreamRedirector streamRedirector(std::cout, ss.rdbuf());
+
     ProfilingOptions options;
     options.m_EnableProfiling          = true;
     armnn::ArmNNProfilingServiceInitialiser initialiser;
@@ -3163,9 +3170,6 @@
     profilingService.Update();
     CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
 
-    // Redirect the output to a local stream so that we can parse the warning message
-    std::stringstream ss;
-    StreamRedirector streamRedirector(std::cout, ss.rdbuf());
     profilingService.Update();
 
     // Reset the profiling service to stop any running thread
@@ -3185,7 +3189,12 @@
 TEST_CASE("CheckProfilingServiceEnabledRuntime")
 {
     // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
-    LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
+    LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
+
+    // Redirect the output to a local stream so that we can parse the warning message
+    std::stringstream ss;
+    StreamRedirector streamRedirector(std::cout, ss.rdbuf());
+
     ProfilingOptions options;
     armnn::ArmNNProfilingServiceInitialiser initialiser;
     ProfilingService profilingService(arm::pipe::MAX_ARMNN_COUNTER, initialiser);
@@ -3199,9 +3208,6 @@
     profilingService.Update();
     CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
 
-    // Redirect the output to a local stream so that we can parse the warning message
-    std::stringstream ss;
-    StreamRedirector streamRedirector(std::cout, ss.rdbuf());
     profilingService.Update();
 
     // Reset the profiling service to stop any running thread
@@ -3221,8 +3227,7 @@
 TEST_CASE("CheckProfilingServiceBadConnectionAcknowledgedPacket")
 {
     // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
-    LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
-
+    LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
 
     // Redirect the standard output to a local stream so that we can parse the warning message
     std::stringstream ss;
@@ -3285,7 +3290,7 @@
 TEST_CASE("CheckProfilingServiceBadRequestCounterDirectoryPacket")
 {
     // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
-    LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
+    LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
 
     // Redirect the standard output to a local stream so that we can parse the warning message
     std::stringstream ss;
@@ -3350,7 +3355,7 @@
 TEST_CASE("CheckProfilingServiceBadPeriodicCounterSelectionPacket")
 {
     // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
-    LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
+    LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
 
     // Redirect the standard output to a local stream so that we can parse the warning message
     std::stringstream ss;
@@ -3707,7 +3712,11 @@
 
 TEST_CASE("CheckFileFormat") {
     // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
-    LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
+    LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Warning);
+
+    // Redirect the output to a local stream so that we can parse the warning message
+    std::stringstream ss;
+    StreamRedirector streamRedirector(std::cout, ss.rdbuf());
 
     // Create profiling options.
     ProfilingOptions options;
@@ -3725,10 +3734,6 @@
     profilingService.Update();
     CHECK(profilingService.GetCurrentState()==ProfilingState::NotConnected);
 
-    // Redirect the output to a local stream so that we can parse the warning message
-    std::stringstream ss;
-    StreamRedirector streamRedirector(std::cout, ss.rdbuf());
-
     // When Update is called and the current state is ProfilingState::NotConnected
     // an exception will be raised from GetProfilingConnection and displayed as warning in the output local stream
     profilingService.Update();
diff --git a/src/profiling/test/ProfilingTests.hpp b/src/profiling/test/ProfilingTests.hpp
index 70bf613..e55117b 100644
--- a/src/profiling/test/ProfilingTests.hpp
+++ b/src/profiling/test/ProfilingTests.hpp
@@ -7,14 +7,13 @@
 
 #include "ProfilingMocks.hpp"
 
-#include <armnn/Logging.hpp>
 #include <armnn/utility/PolymorphicDowncast.hpp>
 
 #include <IProfilingConnection.hpp>
 #include <ProfilingService.hpp>
 
 #include <common/include/CommandHandlerFunctor.hpp>
-
+#include <common/include/Logging.hpp>
 
 #include <doctest/doctest.h>
 
@@ -27,46 +26,6 @@
 namespace pipe
 {
 
-struct LogLevelSwapper
-{
-public:
-    LogLevelSwapper(armnn::LogSeverity severity)
-    {
-        // Set the new log level
-        armnn::ConfigureLogging(true, true, severity);
-    }
-    ~LogLevelSwapper()
-    {
-        // The default log level for unit tests is "Fatal"
-        armnn::ConfigureLogging(true, true, armnn::LogSeverity::Fatal);
-    }
-};
-
-struct StreamRedirector
-{
-public:
-    StreamRedirector(std::ostream& stream, std::streambuf* newStreamBuffer)
-        : m_Stream(stream)
-        , m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
-    {}
-
-    ~StreamRedirector() { CancelRedirect(); }
-
-    void CancelRedirect()
-    {
-        // Only cancel the redirect once.
-        if (m_BackupBuffer != nullptr )
-        {
-            m_Stream.rdbuf(m_BackupBuffer);
-            m_BackupBuffer = nullptr;
-        }
-    }
-
-private:
-    std::ostream& m_Stream;
-    std::streambuf* m_BackupBuffer;
-};
-
 class TestProfilingConnectionBase : public IProfilingConnection
 {
 public:
diff --git a/src/profiling/test/SendTimelinePacketTests.cpp b/src/profiling/test/SendTimelinePacketTests.cpp
index eb6a262..7f2421d 100644
--- a/src/profiling/test/SendTimelinePacketTests.cpp
+++ b/src/profiling/test/SendTimelinePacketTests.cpp
@@ -4,6 +4,7 @@
 //
 
 #include "ProfilingMocks.hpp"
+#include "ProfilingTestUtils.hpp"
 
 #include <ArmNNProfilingServiceInitialiser.hpp>
 #include <BufferManager.hpp>
@@ -428,6 +429,8 @@
 
 TEST_CASE("GetGuidsFromProfilingService")
 {
+    LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
+
     armnn::IRuntime::CreationOptions options;
     options.m_ProfilingOptions.m_EnableProfiling = true;
     armnn::RuntimeImpl runtime(options);
@@ -451,6 +454,8 @@
 
 TEST_CASE("GetTimelinePackerWriterFromProfilingService")
 {
+    LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
+
     ProfilingOptions options;
     options.m_EnableProfiling = true;
     armnn::ArmNNProfilingServiceInitialiser initialiser;