[log] add OT_SHOULD_LOG_AT(aLevel) (#7456)

This commit adds new helper macro `OT_SHOULD_LOG_AT(aLevel)` which
indicates whether logging is enabled at a given log level. This helps
simplify the code and makes sure the the condition used for enabling
logging related functions/methods is consistent across all the core
modules.

With this change, when `OPENTHREAD_CONFIG_LOG_OUTPUT` is set to
`LOG_OUTPUT_NONE` (which practically disables all logging), all the
related code/methods that are used to prepare the log line
(e.g. `Mac::OperationToString()`) are excluded from the build
(become empty functions/methods). This way, under `LOG_OUTPUT = NONE`
instead of preparing the log line and then passing it to an empty
`otPlatLog()` implementation to be dropped, the code is optimized to
not prepare the log line in first place.
This commit is contained in:
Abtin Keshavarzian
2022-03-09 10:38:50 -08:00
committed by GitHub
parent 73eba74fc8
commit 9021935bcc
34 changed files with 141 additions and 106 deletions
+3 -3
View File
@@ -216,7 +216,7 @@ exit:
// LCOV_EXCL_START
#if OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
void Notifier::LogEvents(Events aEvents) const
{
@@ -303,7 +303,7 @@ const char *Notifier::EventToString(Event aEvent) const
return retval;
}
#else // #if OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO
#else // #if OT_SHOULD_LOG_AT( OT_LOG_LEVEL_INFO)
void Notifier::LogEvents(Events) const
{
@@ -314,7 +314,7 @@ const char *Notifier::EventToString(Event) const
return "";
}
#endif // #if OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO
#endif // #if OT_SHOULD_LOG_AT( OT_LOG_LEVEL_INFO)
// LCOV_EXCL_STOP