mirror of
https://github.com/espressif/openthread.git
synced 2026-08-06 02:37:47 +00:00
[core] check if Instance has been initialized before logging (#13099)
When logging while `Instance` has not been initialized yet, use 0 as return value of `GetUptime` and use `OPENTHREAD_CONFIG_LOG_LEVEL_INIT` as default log level instead of accessing raw memory.
This commit is contained in:
+24
-3
@@ -133,7 +133,14 @@ void Logger::Log(const char *aModuleName, LogLevel aLogLevel, Error aError, cons
|
||||
#else
|
||||
#error "OPENTHREAD_CONFIG_LOG_PREPEND_UPTIME requires LOG_INSTANCE_AWARE_API_ENABLE under multi-instance"
|
||||
#endif
|
||||
ot::UptimeToString(instance->Get<ot::UptimeTracker>().GetUptime(), logString, kUptimeStringIncludeMsec);
|
||||
if (instance->IsInitialized())
|
||||
{
|
||||
ot::UptimeToString(instance->Get<ot::UptimeTracker>().GetUptime(), logString, kUptimeStringIncludeMsec);
|
||||
}
|
||||
else
|
||||
{
|
||||
ot::UptimeToString(0, logString, kUptimeStringIncludeMsec);
|
||||
}
|
||||
logString.Append(" ");
|
||||
}
|
||||
#endif
|
||||
@@ -141,7 +148,14 @@ void Logger::Log(const char *aModuleName, LogLevel aLogLevel, Error aError, cons
|
||||
#if OPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE
|
||||
|
||||
#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE
|
||||
VerifyOrExit(Instance::Get().GetLogLevel() >= aLogLevel);
|
||||
if (Instance::Get().IsInitialized())
|
||||
{
|
||||
VerifyOrExit(Instance::Get().GetLogLevel() >= aLogLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
VerifyOrExit(OPENTHREAD_CONFIG_LOG_LEVEL_INIT >= aLogLevel);
|
||||
}
|
||||
#elif !OPENTHREAD_CONFIG_LOG_INSTANCE_AWARE_API_ENABLE
|
||||
VerifyOrExit(Instance::GetGlobalLogLevel() >= aLogLevel);
|
||||
#else
|
||||
@@ -149,7 +163,14 @@ void Logger::Log(const char *aModuleName, LogLevel aLogLevel, Error aError, cons
|
||||
Instance *instance = Instance::GetActiveInstance();
|
||||
|
||||
VerifyOrExit(instance != nullptr);
|
||||
VerifyOrExit(instance->GetLogLevel() >= aLogLevel);
|
||||
if (instance->IsInitialized())
|
||||
{
|
||||
VerifyOrExit(instance->GetLogLevel() >= aLogLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
VerifyOrExit(OPENTHREAD_CONFIG_LOG_LEVEL_INIT >= aLogLevel);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user