Skip to content

Commit

Permalink
[Ameba] Dynamic logging (#25273)
Browse files Browse the repository at this point in the history
* [logging] dynamic log level setting

* [logging] cleaup

* [logging] use enums instead of macros

* [logging] cleanup

* [logging] change loglevel to enum class
- change namespace

* [logging] use to_underlying
- change enum class name

* [logging] fix compile errors
- change back the namespace to chip::Logging::Platform
  • Loading branch information
pankore authored and pull[bot] committed Feb 14, 2024
1 parent 6d97446 commit 1355576
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
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

0 comments on commit 1355576

Please sign in to comment.