mirror of
https://github.com/espressif/openthread.git
synced 2026-10-21 23:18:17 +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:
@@ -90,6 +90,25 @@ void platformLoggingDeinit(void)
|
||||
}
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE
|
||||
|
||||
void otPlatLogOutput(otInstance *aInstance, otLogLevel aLogLevel, const char *aLogLine)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
|
||||
if (sLogFile == NULL)
|
||||
{
|
||||
syslog(LOG_CRIT, "[%lu] %s", (unsigned long)gNodeId, aLogLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(sLogFile, "%s\r\n", aLogLine);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
@@ -118,9 +137,11 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
#else
|
||||
#endif // OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE
|
||||
|
||||
#else // (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED)
|
||||
|
||||
void platformLoggingInit(const char *aName) { OT_UNUSED_VARIABLE(aName); }
|
||||
void platformLoggingDeinit(void) {}
|
||||
|
||||
#endif // (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED)
|
||||
#endif
|
||||
|
||||
@@ -120,6 +120,15 @@ otError otPlatDebugUart_logfile(const char *filename)
|
||||
}
|
||||
|
||||
#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_DEBUG_UART)
|
||||
|
||||
#if OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE
|
||||
void otPlatLogOutput(otInstance *aInstance, otLogLevel aLogLevel, const char *aLogLine)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
otPlatLog(aLogLevel, OT_LOG_REGION_CORE, "%s", aLogLine);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* this should not be a WEAK function */
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user