Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log node ID in exchanges #32550

Merged
merged 6 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading