Skip to content

Commit

Permalink
Split JSON log tracing line by line for better alignment (project-chi…
Browse files Browse the repository at this point in the history
…p#28897)

* Better tracing (split log lines, make decoder resilient, fix protocol typo

* Restyle

* Fix more list formats

---------

Co-authored-by: Andrei Litvin <andreilitvin@google.com>
  • Loading branch information
andy31415 and andreilitvin authored Aug 26, 2023
1 parent 7e3c820 commit 2d5fe2c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions src/lib/format/protocol_messages.matter
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/tracing/json/json_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <lib/support/CHIPMem.h>
#include <lib/support/ErrorStr.h>
#include <lib/support/StringBuilder.h>
#include <lib/support/StringSplitter.h>
#include <transport/TracingStructs.h>

#include <log_json/log_json_build_config.h>
Expand Down Expand Up @@ -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<int>(line.size()), line.data());
}
}
}

Expand Down

0 comments on commit 2d5fe2c

Please sign in to comment.