Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ameba] Dynamic logging #25273

Merged
merged 7 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/platform/Ameba/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,30 @@
#include <platform/logging/LogV.h>

#include <core/CHIPConfig.h>
#include <support/TypeTraits.h>
#include <support/logging/Constants.h>

#include "Logging.h"
#include <stdio.h>

#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];
Expand All @@ -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;
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/platform/Ameba/Logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <platform_stdlib.h>

namespace chip {
namespace Logging {
namespace Platform {

enum class LogLevel
{
kError,
kProgress,
kDetail,
};

void LogSetLevel(LogLevel level);
LogLevel LogGetLevel();

} // namespace Platform
} // namespace Logging
} // namespace chip