From 2d5fe2ce434f5d0f7714d55e67914e3e8ebf5827 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Sat, 26 Aug 2023 10:36:54 -0400 Subject: [PATCH] Split JSON log tracing line by line for better alignment (#28897) * Better tracing (split log lines, make decoder resilient, fix protocol typo * Restyle * Fix more list formats --------- Co-authored-by: Andrei Litvin --- .../matter_chip_tool_adapter/decoder.py | 2 +- src/lib/format/protocol_messages.matter | 8 ++++---- src/tracing/json/json_tracing.cpp | 11 ++++++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py b/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py index 0ee564203ba86a..ec9b4702de0a3d 100644 --- a/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py +++ b/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py @@ -133,7 +133,7 @@ def __init__(self, log): base64_message = log["message"].encode('utf-8') decoded_message_bytes = base64.b64decode(base64_message) # TODO We do assume utf-8 encoding is used, it may not be true though. - self.message = decoded_message_bytes.decode('utf-8') + self.message = decoded_message_bytes.decode('utf-8', 'replace') def decode_logs(logs): return list(map(MatterLog, logs)) diff --git a/src/lib/format/protocol_messages.matter b/src/lib/format/protocol_messages.matter index 786c50d85dffb0..30ffa0e1d7704e 100644 --- a/src/lib/format/protocol_messages.matter +++ b/src/lib/format/protocol_messages.matter @@ -174,12 +174,12 @@ client cluster IMProtocol = 0xFFFF0001 { boolean keep_subscriptions = 0; int16u min_minterval_floor = 1; int16u max_minterval_ceiling = 2; - optional AttributePathIB attribute_requests = 3; - optional EventPathIB event_requests = 4; - optional EventFilterIB event_filters = 5; + optional AttributePathIB attribute_requests[] = 3; + optional EventPathIB event_requests[] = 4; + optional EventFilterIB event_filters[] = 5; // NOTE: 6 is missing here ... boolean fabric_filtered = 7; - optional DataVersionFilterIB data_version_filters = 8; + optional DataVersionFilterIB data_version_filters[] = 8; // 10.2.2.2. Context Tag Encoded Action Information int8u interaction_model_revison = 0xFF; diff --git a/src/tracing/json/json_tracing.cpp b/src/tracing/json/json_tracing.cpp index 9750378df29ea7..204ca8fa742aa6 100644 --- a/src/tracing/json/json_tracing.cpp +++ b/src/tracing/json/json_tracing.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -444,7 +445,15 @@ void JsonBackend::OutputValue(::Json::Value & value) { std::stringstream output; writer->write(value, &output); - ChipLogProgress(Automation, "%s", output.str().c_str()); + // For pretty-printing, output each log line individually. + std::string data_string = output.str(); + chip::StringSplitter splitter(data_string.c_str(), '\n'); + + chip::CharSpan line; + while (splitter.Next(line)) + { + ChipLogProgress(Automation, "%.*s", static_cast(line.size()), line.data()); + } } }