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 4 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
26 changes: 19 additions & 7 deletions src/platform/Ameba/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,25 @@
#include <core/CHIPConfig.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 {

static uint8_t LogLevel = AmebaLogLevel::ameba_loglevel_detail;

void LogSetLevel(uint8_t level)
{
LogLevel = level;
}

uint8_t LogGetLevel()
{
return LogLevel;
}

void LogV(const char * module, uint8_t category, const char * msg, va_list v)
{
char tag[11];
Expand All @@ -50,14 +59,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 (LogLevel >= AmebaLogLevel::ameba_loglevel_error)
printf("%s %s\r\n", tag, formattedMsg);
break;
case kLogCategory_Progress:
default:
printf("%s %s\r\n", tag, formattedMsg);
if (LogLevel >= AmebaLogLevel::ameba_loglevel_progress)
printf("%s %s\r\n", tag, formattedMsg);
break;
case kLogCategory_Detail:
printf("%s %s\r\n", tag, formattedMsg);
if (LogLevel >= AmebaLogLevel::ameba_loglevel_detail)
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 AmebaLogLevel
pankore marked this conversation as resolved.
Show resolved Hide resolved
{
ameba_loglevel_error = 0,
ameba_loglevel_progress,
ameba_loglevel_detail,
};

void LogSetLevel(uint8_t level);
pankore marked this conversation as resolved.
Show resolved Hide resolved
uint8_t LogGetLevel();

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