[logging] introduce Log{Level}OnError macros and update core (#12533)

This commit introduces a new set of logging macros, `LogCritOnError`,
`LogWarnOnError`, `LogNoteOnError`, `LogInfoOnError`, and
`LogDebgOnError`, to provide a consistent and streamlined way to log
errors across the codebase.

The new macros automatically prepend "Failed to " and append the error
string (using `ErrorToString()`) to the log message, reducing
boilerplate code and ensuring a uniform log format. These macros only
emit a log if the provided `Error` is not `kErrorNone`.

This change improves code readability and maintainability by
consolidating error logging logic into the logging framework.
This commit is contained in:
Abtin Keshavarzian
2026-02-24 15:10:33 -06:00
committed by GitHub
parent 632669f1c1
commit 65c1b97342
24 changed files with 171 additions and 170 deletions
+2 -2
View File
@@ -1947,8 +1947,8 @@ Error Mle::ProcessAddressRegistrationTlv(RxInfo &aRxInfo, Child &aChild)
}
else
{
LogWarn("Error %s adding IPv6 address %s to child 0x%04x", ErrorToString(error),
address.ToString().AsCString(), aChild.GetRloc16());
LogWarnOnError(error, "add IPv6 address %s to child 0x%04x", address.ToString().AsCString(),
aChild.GetRloc16());
}
if (address.IsMulticast())