From 3852ac3d3e10602470a52d98c5c243595c8d9eb2 Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Sat, 13 Mar 2021 01:22:19 +0800 Subject: [PATCH] [logging] refine BBR log level (#6270) This commit refines BBR log level usage using otLogResultBbr. --- src/core/backbone_router/backbone_tmf.cpp | 19 +++---------------- src/core/backbone_router/bbr_manager.cpp | 9 +-------- src/core/common/logging.hpp | 14 +++++++++++++- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/core/backbone_router/backbone_tmf.cpp b/src/core/backbone_router/backbone_tmf.cpp index 75ff364a5..779c9a63f 100644 --- a/src/core/backbone_router/backbone_tmf.cpp +++ b/src/core/backbone_router/backbone_tmf.cpp @@ -36,6 +36,7 @@ #if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE #include "common/locator-getters.hpp" +#include "common/logging.hpp" namespace ot { namespace BackboneRouter { @@ -83,14 +84,7 @@ void BackboneTmfAgent::SubscribeMulticast(const Ip6::Address &aAddress) error = mSocket.JoinNetifMulticastGroup(OT_NETIF_BACKBONE, aAddress); - if (error != OT_ERROR_NONE) - { - otLogDebgBbr("Backbone TMF subscribes %s: %s", aAddress.ToString().AsCString(), otThreadErrorToString(error)); - } - else - { - otLogCritBbr("Backbone TMF subscribes %s: %s", aAddress.ToString().AsCString(), otThreadErrorToString(error)); - } + otLogResultBbr(error, "Backbone TMF subscribes %s", aAddress.ToString().AsCString()); } void BackboneTmfAgent::UnsubscribeMulticast(const Ip6::Address &aAddress) @@ -99,14 +93,7 @@ void BackboneTmfAgent::UnsubscribeMulticast(const Ip6::Address &aAddress) error = mSocket.LeaveNetifMulticastGroup(OT_NETIF_BACKBONE, aAddress); - if (error == OT_ERROR_NONE) - { - otLogDebgBbr("Backbone TMF unsubscribes %s: %s", aAddress.ToString().AsCString(), otThreadErrorToString(error)); - } - else - { - otLogCritBbr("Backbone TMF unsubscribes %s: %s", aAddress.ToString().AsCString(), otThreadErrorToString(error)); - } + otLogResultBbr(error, "Backbone TMF unsubscribes %s", aAddress.ToString().AsCString()); } } // namespace BackboneRouter diff --git a/src/core/backbone_router/bbr_manager.cpp b/src/core/backbone_router/bbr_manager.cpp index af709d118..e435be1d8 100644 --- a/src/core/backbone_router/bbr_manager.cpp +++ b/src/core/backbone_router/bbr_manager.cpp @@ -129,14 +129,7 @@ void Manager::HandleNotifierEvents(Events aEvents) error = mBackboneTmfAgent.Start(); - if (error != OT_ERROR_NONE) - { - otLogCritBbr("Start Backbone TMF agent: %s", otThreadErrorToString(error)); - } - else - { - otLogInfoBbr("Start Backbone TMF agent: %s", otThreadErrorToString(error)); - } + otLogResultBbr(error, "Start Backbone TMF agent"); } } } diff --git a/src/core/common/logging.hpp b/src/core/common/logging.hpp index 2eca1e0cc..7bdf3875e 100644 --- a/src/core/common/logging.hpp +++ b/src/core/common/logging.hpp @@ -2565,7 +2565,19 @@ const char *otLogLevelToPrefixString(otLogLevel aLogLevel); * @param[in] ... Arguments for the format specification. * */ -#define otLogResultPlat(aError, ...) _otLogResult(Plat, aError, OT_FIRST_ARG(__VA_ARGS__) OT_REST_ARGS(__VA_ARGS__)) +#define otLogResultPlat(aError, ...) _otLogResult(Plat, aError, __VA_ARGS__) + +/** + * @def otLogResultBbr + * + * This function generates a log for the BBR region according to the error result. If @p aError is `OT_ERROR_NONE`, the + * log level is info. Otherwise the log level is warn. + * + * @param[in] aError The error result. + * @param[in] ... Arguments for the format specification. + * + */ +#define otLogResultBbr(aError, ...) _otLogResult(Bbr, aError, __VA_ARGS__) #ifdef __cplusplus }