Skip to content

Commit

Permalink
Log node ID in exchanges (project-chip#32550)
Browse files Browse the repository at this point in the history
* Log nodeID in exchange context

* Update comments

* Use ChipLogValueScopedNodeId with ScopedNodeId instead of SubjectDescriptor

* Make node id logging optional

* Restyled by whitespace

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
leonardmgh and restyled-commits authored Mar 19, 2024
1 parent f86633b commit a0ba592
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
14 changes: 11 additions & 3 deletions src/lib/support/logging/TextOnlyLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,24 @@ using LogRedirectCallback_t = void (*)(const char * module, uint8_t category, co
#define ChipLogValueMEI(aValue) static_cast<uint16_t>(aValue >> 16), static_cast<uint16_t>(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.
Expand Down

0 comments on commit a0ba592

Please sign in to comment.