diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h index 2de6a662ee8c4d..558e0ee08e4605 100644 --- a/src/lib/core/CHIPConfig.h +++ b/src/lib/core/CHIPConfig.h @@ -461,6 +461,16 @@ #define CHIP_CONFIG_ENABLE_CONDITION_LOGGING 0 #endif // CHIP_CONFIG_ENABLE_CONDITION_LOGGING +/** + * @def CHIP_EXCHANGE_NODE_ID_LOGGING + * + * @brief + * If asserted (1), enable logging of node IDs in exchange context. + */ +#ifndef CHIP_EXCHANGE_NODE_ID_LOGGING +#define CHIP_EXCHANGE_NODE_ID_LOGGING 0 +#endif // CHIP_EXCHANGE_NODE_ID_LOGGING + /** * @def CHIP_CONFIG_TEST * diff --git a/src/lib/support/logging/TextOnlyLogging.h b/src/lib/support/logging/TextOnlyLogging.h index d6b22f7c6c5a6b..b0abef9d00e722 100644 --- a/src/lib/support/logging/TextOnlyLogging.h +++ b/src/lib/support/logging/TextOnlyLogging.h @@ -268,16 +268,24 @@ using LogRedirectCallback_t = void (*)(const char * module, uint8_t category, co #define ChipLogValueMEI(aValue) static_cast(aValue >> 16), static_cast(aValue) /** - * Logging helpers for exchanges. For now just log the exchange id and whether - * it's an initiator or responder, but eventually we may want to log the peer - * node id as well (especially for the responder case). Some callsites only + * Logging helpers for exchanges. Log the exchange id, whether + * it's an initiator or responder and the scoped node. Some callsites only * have the exchange id and initiator/responder boolean, not an actual exchange, * so we want to have a helper for that case too. */ #define ChipLogFormatExchangeId "%u%c" #define ChipLogValueExchangeId(id, isInitiator) id, ((isInitiator) ? 'i' : 'r') + +#if CHIP_EXCHANGE_NODE_ID_LOGGING +#define ChipLogFormatExchange ChipLogFormatExchangeId " with Node: " ChipLogFormatScopedNodeId +#define ChipLogValueExchange(ec) \ + ChipLogValueExchangeId((ec)->GetExchangeId(), (ec)->IsInitiator()), \ + ChipLogValueScopedNodeId((ec)->HasSessionHandle() ? (ec)->GetSessionHandle()->GetPeer() : ScopedNodeId()) +#else // CHIP_EXCHANGE_NODE_ID_LOGGING #define ChipLogFormatExchange ChipLogFormatExchangeId #define ChipLogValueExchange(ec) ChipLogValueExchangeId((ec)->GetExchangeId(), (ec)->IsInitiator()) +#endif // CHIP_EXCHANGE_NODE_ID_LOGGING + #define ChipLogValueExchangeIdFromSentHeader(payloadHeader) \ ChipLogValueExchangeId((payloadHeader).GetExchangeID(), (payloadHeader).IsInitiator()) // A received header's initiator boolean is the inverse of the exchange's.