mirror of
https://github.com/espressif/openthread.git
synced 2026-08-16 07:37:47 +00:00
[logging] add optional otPlatLogLine() & use it in NCP/CLI (#5704)
This commit adds a new platform function `otPlatLogLine()`. This function is optional and if not implemented by platform layer, a default weak implementation is provided and used by the OpenThread core using `otPlatLog()`.The new function is used by OpenThread core when the feature `OPENTHREAD_CONFIG_LOG_DEFINE_AS_MACRO_ONLY` is not enabled (which is the default behavior). In this case, the OT core itself will prepare a full log line. This commit also adds implementations of the new platform function for the NCP and CLI modules.
This commit is contained in:
@@ -133,13 +133,15 @@ pseudo_reset:
|
||||
#if OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_APP
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
OT_UNUSED_VARIABLE(aFormat);
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, aFormat);
|
||||
otCliPlatLogv(aLogLevel, aLogRegion, aFormat, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void otPlatLogLine(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aLogLine)
|
||||
{
|
||||
otCliPlatLogLine(aLogLevel, aLogRegion, aLogLine);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -164,6 +164,16 @@ void otCliAppendResult(otError aError);
|
||||
*/
|
||||
void otCliPlatLogv(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list aArgs);
|
||||
|
||||
/**
|
||||
* Function to write the OpenThread Log to the CLI console.
|
||||
*
|
||||
* @param[in] aLogLevel The log level.
|
||||
* @param[in] aLogRegion The log region.
|
||||
* @param[in] aLogLine A pointer to the log line string.
|
||||
*
|
||||
*/
|
||||
void otCliPlatLogLine(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aLogLine);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
||||
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (39)
|
||||
#define OPENTHREAD_API_VERSION (40)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -150,6 +150,22 @@ typedef enum otLogRegion
|
||||
*/
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...);
|
||||
|
||||
/**
|
||||
* This (optional) platform function outputs a prepared log line.
|
||||
*
|
||||
* This platform function is used by OpenThread core when `OPENTHREAD_CONFIG_LOG_DEFINE_AS_MACRO_ONLY` is not enabled
|
||||
* (in this case, the OT core itself will prepare a full log line).
|
||||
*
|
||||
* Note that this function is optional and if not provided by platform layer, a default (weak) implementation is
|
||||
* provided and used by OpenThread core as `otPlatLog(aLogLevel, aLogResion, "%s", aLogLine)`.
|
||||
*
|
||||
* @param[in] aLogLevel The log level.
|
||||
* @param[in] aLogRegion The log region.
|
||||
* @param[in] aLogLine A pointer to a log line string.
|
||||
*
|
||||
*/
|
||||
void otPlatLogLine(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aLogLine);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
||||
@@ -4641,6 +4641,18 @@ exit:
|
||||
return;
|
||||
}
|
||||
|
||||
extern "C" void otCliPlatLogLine(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aLogLine)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
|
||||
VerifyOrExit(Interpreter::IsInitialized());
|
||||
Interpreter::GetInterpreter().OutputLine(aLogLine);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace Cli
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -390,6 +390,11 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat
|
||||
}
|
||||
#endif
|
||||
|
||||
OT_TOOL_WEAK void otPlatLogLine(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aLogLine)
|
||||
{
|
||||
otPlatLog(aLogLevel, aLogRegion, "%s", aLogLine);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2469,4 +2469,14 @@ extern "C" void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const ch
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
extern "C" void otPlatLogLine(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aLogLine)
|
||||
{
|
||||
ot::Ncp::NcpBase *ncp = ot::Ncp::NcpBase::GetNcpInstance();
|
||||
|
||||
if (ncp != nullptr)
|
||||
{
|
||||
ncp->Log(aLogLevel, aLogRegion, aLogLine);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_APP)
|
||||
|
||||
Reference in New Issue
Block a user