// // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #include #include #include #include #if defined(_MSC_VER) #include #endif #if defined(__ANDROID__) #include #endif #include namespace armnn { void SetLogFilter(LogSeverity level) { SimpleLogger::Get().Enable(false); SimpleLogger::Get().Enable(false); SimpleLogger::Get().Enable(false); SimpleLogger::Get().Enable(false); SimpleLogger::Get().Enable(false); SimpleLogger::Get().Enable(false); switch (level) { case LogSeverity::Trace: SimpleLogger::Get().Enable(true); ARMNN_FALLTHROUGH; case LogSeverity::Debug: SimpleLogger::Get().Enable(true); ARMNN_FALLTHROUGH; case LogSeverity::Info: SimpleLogger::Get().Enable(true); ARMNN_FALLTHROUGH; case LogSeverity::Warning: SimpleLogger::Get().Enable(true); ARMNN_FALLTHROUGH; case LogSeverity::Error: SimpleLogger::Get().Enable(true); ARMNN_FALLTHROUGH; case LogSeverity::Fatal: SimpleLogger::Get().Enable(true); break; default: ARMNN_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 inline void SetLoggingSinks(bool standardOut, bool debugOut, bool coloured) { SimpleLogger::Get().RemoveAllSinks(); if (standardOut) { if (coloured) { SimpleLogger::Get().AddSink( std::make_shared(Level)); } else { SimpleLogger::Get().AddSink( std::make_shared()); } } if (debugOut) { SimpleLogger::Get().AddSink( std::make_shared()); } } void SetAllLoggingSinks(bool standardOut, bool debugOut, bool coloured) { SetLoggingSinks(standardOut, debugOut, coloured); SetLoggingSinks(standardOut, debugOut, coloured); SetLoggingSinks(standardOut, debugOut, coloured); SetLoggingSinks(standardOut, debugOut, coloured); SetLoggingSinks(standardOut, debugOut, coloured); SetLoggingSinks(standardOut, debugOut, coloured); } } //namespace armnn