Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

[RFC] JSON output #178

Closed
japaric opened this issue Mar 26, 2021 · 0 comments · Fixed by knurling-rs/defmt#651
Closed

[RFC] JSON output #178

japaric opened this issue Mar 26, 2021 · 0 comments · Fixed by knurling-rs/defmt#651
Assignees
Labels
difficulty: medium Somewhat difficult to solve priority: medium Medium priority for the Knurling team status: needs PR Issue just needs a Pull Request implementing the changes type: enhancement Enhancement or feature request

Comments

@japaric
Copy link
Member

japaric commented Mar 26, 2021

Summary

Add a --json flag to probe-run to change the output from colored, rendered text (default) to JSON output.
The goal is to allow inter-operation with other command line tools (e.g. store in database) using JSON as an exchange format.

Detailed design: JSON schema

This Rust code:

fn function_name() {
    struct MyStruct { x: i32, y: bool }
    let x = 42;
    info!("the {} is {}", "answer", MyStruct { x, y: true });
}

Produces the following JSON object

{
  // source code location
  "location": {
    // path may be relative or absolute
    "file": "src/main.rs",
    "line": 104,
    "column": 8,
  },

  // host-side date-time at which the log was *retrieved* in RFC3339 or similar
  "host_timestamp": "2021-03-25 18:04:34+01:00",

  // target-side uptime timestamp at which the log was *emitted*
  // `null` if timestamp is omitted or custom timestamp format is used (not the `:us` hint)
  "target_timestamp": {
    "secs": 1,
    "nanos": 1234,
  },

  // Full item path to the function that contains the log statement
  // in Rust syntax: `crate_name::outer_module::inner_module::function_name`
  "path": {
      "crate": "crate_name",
      "modules": ["outer_module", "inner_module"],
      "function": "function_name",
      // check for presence of `{{impl}}` in segment retrieved from DWARF
      "is_method": false,
  }

  // 5 levels: [error, warn, info, debug, trace]
  "level": "info",

  // formatted log message
  "data": "the answer is MyStruct { x: 42, y: true }",

  // iff the log message comes from `#[panic_handler]`; otherwise `null`
  // array of stack frames
  "backtrace": [
     {
       "path": {}, // same as outer `.path` field
       "location": {}, // same as outer `.location` field
     },
     // ..
  ]
}

NOTE No attempt to include structured data in the JSON object is v1.
v2 or later may contain format string + structured data (e.g. structs becomes JSON maps, etc.)

Unresolved questions

  • --output=json1 instead --json=v1?
  • micros instead of nanos?
@Urhengulas Urhengulas added difficulty: medium Somewhat difficult to solve priority: medium Medium priority for the Knurling team status: needs PR Issue just needs a Pull Request implementing the changes type: enhancement Enhancement or feature request labels Mar 26, 2021
@Urhengulas Urhengulas added this to Incoming in Issue Triage via automation Mar 26, 2021
@Urhengulas Urhengulas moved this from Incoming to Triaged in Issue Triage Mar 28, 2021
@Urhengulas Urhengulas self-assigned this Jul 5, 2021
@Urhengulas Urhengulas assigned Urhengulas and unassigned Urhengulas Jan 4, 2022
Issue Triage automation moved this from Triaged to Closed Jan 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
difficulty: medium Somewhat difficult to solve priority: medium Medium priority for the Knurling team status: needs PR Issue just needs a Pull Request implementing the changes type: enhancement Enhancement or feature request
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants