diff --git a/src/platform/Ameba/Logging.cpp b/src/platform/Ameba/Logging.cpp index 5bd55a72e94b37..edafd0f8a962e6 100644 --- a/src/platform/Ameba/Logging.cpp +++ b/src/platform/Ameba/Logging.cpp @@ -25,18 +25,30 @@ #include #include +#include #include +#include "Logging.h" #include -#ifdef LOG_LOCAL_LEVEL -#undef LOG_LOCAL_LEVEL -#endif - namespace chip { namespace Logging { namespace Platform { +namespace { +LogLevel log_level = LogLevel::kDetail; +} + +void LogSetLevel(LogLevel level) +{ + log_level = level; +} + +LogLevel LogGetLevel() +{ + return log_level; +} + void LogV(const char * module, uint8_t category, const char * msg, va_list v) { char tag[11]; @@ -50,14 +62,17 @@ void LogV(const char * module, uint8_t category, const char * msg, va_list v) switch (category) { case kLogCategory_Error: - printf("%s %s\r\n", tag, formattedMsg); + if (to_underlying(log_level) >= to_underlying(LogLevel::kError)) + printf("%s %s\r\n", tag, formattedMsg); break; case kLogCategory_Progress: default: - printf("%s %s\r\n", tag, formattedMsg); + if (to_underlying(log_level) >= to_underlying(LogLevel::kProgress)) + printf("%s %s\r\n", tag, formattedMsg); break; case kLogCategory_Detail: - printf("%s %s\r\n", tag, formattedMsg); + if (to_underlying(log_level) >= to_underlying(LogLevel::kDetail)) + printf("%s %s\r\n", tag, formattedMsg); break; } } diff --git a/src/platform/Ameba/Logging.h b/src/platform/Ameba/Logging.h new file mode 100644 index 00000000000000..dca1bed9d6aa6e --- /dev/null +++ b/src/platform/Ameba/Logging.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +namespace chip { +namespace Logging { +namespace Platform { + +enum class LogLevel +{ + kError, + kProgress, + kDetail, +}; + +void LogSetLevel(LogLevel level); +LogLevel LogGetLevel(); + +} // namespace Platform +} // namespace Logging +} // namespace chip