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 2 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
22 changes: 19 additions & 3 deletions src/platform/Ameba/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <core/CHIPConfig.h>
#include <support/logging/Constants.h>

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

#ifdef LOG_LOCAL_LEVEL
pankore marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -37,6 +38,18 @@ namespace chip {
namespace Logging {
namespace Platform {

static uint8_t LogLevel = 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 +63,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 >= AMEBA_LOGLEVEL_ERROR)
printf("%s %s\r\n", tag, formattedMsg);
break;
case kLogCategory_Progress:
default:
printf("%s %s\r\n", tag, formattedMsg);
if (LogLevel >= AMEBA_LOGLEVEL_PROGRESS)
printf("%s %s\r\n", tag, formattedMsg);
break;
case kLogCategory_Detail:
printf("%s %s\r\n", tag, formattedMsg);
if (LogLevel >= AMEBA_LOGLEVEL_DETAIL)
printf("%s %s\r\n", tag, formattedMsg);
break;
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/platform/Ameba/Logging.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <platform_stdlib.h>

#define AMEBA_LOGLEVEL_ERROR 1
pankore marked this conversation as resolved.
Show resolved Hide resolved
#define AMEBA_LOGLEVEL_PROGRESS 2
#define AMEBA_LOGLEVEL_DETAIL 3

namespace chip {
namespace Logging {
namespace Platform {

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

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