mirror of
https://github.com/espressif/openthread.git
synced 2026-10-14 03:37:40 +00:00
[platform] implement otPlatLogOutput platform API (#12762)
This commit provides the platform-level implementation for the instance-aware logging API `otPlatLogOutput()`. This API is used when `OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE` is enabled, allowing the platform to receive the `otInstance` pointer with each log line. The new API is implemented across: - The simulation platform logging. - The POSIX platform using `syslog()`. - The NCP base to route logs to the NCP host. - The CLI logging module. - Unit tests and mock platforms. The `OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE` configuration is also enabled for Toranj simulations to support multi-instance log testing.
This commit is contained in:
@@ -496,6 +496,8 @@ void otPlatDiagRadioReceived(otInstance *, otRadioFrame *, otError) {}
|
||||
|
||||
void otPlatDiagAlarmCallback(otInstance *) {}
|
||||
|
||||
OT_TOOL_WEAK void otPlatLogOutput(otInstance *, otLogLevel, const char *) {}
|
||||
|
||||
OT_TOOL_WEAK void otPlatLog(otLogLevel, otLogRegion, const char *, ...) {}
|
||||
|
||||
void *otPlatCAlloc(size_t aNum, size_t aSize) { return calloc(aNum, aSize); }
|
||||
|
||||
@@ -89,6 +89,8 @@
|
||||
|
||||
#define OPENTHREAD_CONFIG_LOG_OUTPUT OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED
|
||||
|
||||
#define OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE 1
|
||||
|
||||
#define OPENTHREAD_CONFIG_CLI_LOG_INPUT_OUTPUT_ENABLE 1
|
||||
|
||||
#define OPENTHREAD_CONFIG_CLI_LOG_INPUT_OUTPUT_LEVEL OT_LOG_LEVEL_INFO
|
||||
|
||||
@@ -69,11 +69,11 @@ void AdvanceNowTo(uint32_t aNewNow);
|
||||
extern "C" {
|
||||
|
||||
#if OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
#if OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE
|
||||
void otPlatLogOutput(otInstance *, otLogLevel, const char *aLogLine) { printf(" %s\n", aLogLine); }
|
||||
#else
|
||||
void otPlatLog(otLogLevel, otLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
|
||||
va_list args;
|
||||
|
||||
printf(" ");
|
||||
@@ -83,6 +83,7 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
// otPlatAlarams
|
||||
|
||||
@@ -138,11 +138,11 @@ void otPlatFree(void *aPtr)
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
#if OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE
|
||||
void otPlatLogOutput(otInstance *, otLogLevel, const char *aLogLine) { printf(" %s\n", aLogLine); }
|
||||
#else
|
||||
void otPlatLog(otLogLevel, otLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
|
||||
va_list args;
|
||||
|
||||
printf(" ");
|
||||
@@ -152,6 +152,7 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
} // extern "C"
|
||||
|
||||
|
||||
@@ -139,11 +139,11 @@ void otPlatFree(void *aPtr)
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
#if OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE
|
||||
void otPlatLogOutput(otInstance *, otLogLevel, const char *aLogLine) { printf(" %s\n", aLogLine); }
|
||||
#else
|
||||
void otPlatLog(otLogLevel, otLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
|
||||
va_list args;
|
||||
|
||||
printf(" ");
|
||||
@@ -153,6 +153,7 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
} // extern "C"
|
||||
|
||||
|
||||
+10
-10
@@ -1677,26 +1677,26 @@ static void SendEmtryPtrQueryWithKnownAnswers(const char *aName, const KnownAnsw
|
||||
|
||||
extern "C" {
|
||||
|
||||
#if OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
OT_UNUSED_VARIABLE(aFormat);
|
||||
|
||||
#if ENABLE_TEST_LOG
|
||||
|
||||
#if OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED
|
||||
#if OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE
|
||||
void otPlatLogOutput(otInstance *, otLogLevel, const char *aLogLine) { printf(" %s\n", aLogLine); }
|
||||
#else
|
||||
void otPlatLog(otLogLevel, otLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
printf(" ");
|
||||
va_start(args, aFormat);
|
||||
vprintf(aFormat, args);
|
||||
va_end(args);
|
||||
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // ENABLE_TEST_LOG
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
// `otPlatAlarm`
|
||||
|
||||
@@ -280,6 +280,8 @@ OT_TOOL_WEAK otPlatResetReason otPlatGetResetReason(otInstance *) { return OT_PL
|
||||
|
||||
OT_TOOL_WEAK void otPlatWakeHost(void) {}
|
||||
|
||||
OT_TOOL_WEAK void otPlatLogOutput(otInstance *, otLogLevel, const char *) {}
|
||||
|
||||
OT_TOOL_WEAK void otPlatLog(otLogLevel, otLogRegion, const char *, ...) {}
|
||||
|
||||
OT_TOOL_WEAK void otPlatSettingsInit(otInstance *, const uint16_t *, uint16_t) {}
|
||||
|
||||
@@ -242,11 +242,11 @@ void DiscoverNat64Prefix(const Ip6::Prefix &aPrefix);
|
||||
extern "C" {
|
||||
|
||||
#if OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
#if OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE
|
||||
void otPlatLogOutput(otInstance *, otLogLevel, const char *aLogLine) { printf(" %s\n", aLogLine); }
|
||||
#else
|
||||
void otPlatLog(otLogLevel, otLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
|
||||
va_list args;
|
||||
|
||||
printf(" ");
|
||||
@@ -256,6 +256,7 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
// `otPlatRadio
|
||||
|
||||
@@ -458,11 +458,11 @@ void otPlatFree(void *aPtr)
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
#if OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE
|
||||
void otPlatLogOutput(otInstance *, otLogLevel, const char *aLogLine) { printf(" %s\n", aLogLine); }
|
||||
#else
|
||||
void otPlatLog(otLogLevel, otLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
|
||||
va_list args;
|
||||
|
||||
printf(" ");
|
||||
@@ -472,6 +472,7 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
} // extern "C"
|
||||
|
||||
|
||||
@@ -134,11 +134,11 @@ void otPlatFree(void *aPtr)
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
#if OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE
|
||||
void otPlatLogOutput(otInstance *, otLogLevel, const char *aLogLine) { printf(" %s\n", aLogLine); }
|
||||
#else
|
||||
void otPlatLog(otLogLevel, otLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
|
||||
va_list args;
|
||||
|
||||
printf(" ");
|
||||
@@ -148,6 +148,7 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
} // extern "C"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user