[Lldb-commits] [lldb] [lldb] Add option to log in JSONL format (PR #205758)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 25 02:50:45 PDT 2026


================
@@ -335,6 +336,47 @@ TEST_F(LogChannelEnabledTest, log_options) {
             logAndTakeOutput("Hello World"));
 }
 
+TEST_F(LogChannelEnabledTest, JSONLOutput) {
+  std::string Err;
+
+  // With only the JSON flag set, every line must parse as JSON and contain
+  // exactly the message we logged.
+  EXPECT_TRUE(
+      EnableChannel(getLogHandler(), LLDB_LOG_OPTION_JSON, "chan", {}, Err));
+  llvm::StringRef Msg = logAndTakeOutput("Hello \"World\"\nsecond line");
+  ASSERT_TRUE(Msg.ends_with("\n"));
+  ASSERT_EQ(Msg.count('\n'), 1u) << "expected one JSON object per line";
+  llvm::Expected<llvm::json::Value> Parsed = llvm::json::parse(Msg);
+  ASSERT_TRUE(static_cast<bool>(Parsed)) << llvm::toString(Parsed.takeError());
+  llvm::json::Object *Obj = Parsed->getAsObject();
+  ASSERT_NE(Obj, nullptr);
+  llvm::StringRef Got = Obj->getString("message").value_or("");
+  EXPECT_EQ(Got, "Hello \"World\"\nsecond line");
+  EXPECT_EQ(Obj->size(), 1u);
+
+  // Combining JSON with metadata flags: each metadata flag becomes a JSON
+  // field instead of a prefix on the line.
----------------
DavidSpickett wrote:

Could you enable one of them in the check above, so that we can see the difference?

Also proves that the json option just redirects the original output, rather than skipping the extras.

https://github.com/llvm/llvm-project/pull/205758


More information about the lldb-commits mailing list