Skip to content

Commit

Permalink
fix: output in jsonl format fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
cvandeplas committed Jun 11, 2024
1 parent 3e87dfa commit f6c495d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/unifiedlog_parser_json/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,17 +344,19 @@ fn parse_trace_file(
println!("Parsed {} log entries", log_count);
}

// Create JSON files
// Create JSON files in jsonl format
fn output(results: &Vec<LogData>, output_name: &str) -> Result<(), Box<dyn Error>> {
let args = Args::parse();
let mut json_file = OpenOptions::new()
.append(true)
.create(true)
.open(format!("{}/{}.json", args.output, output_name))?;

let serde_data = serde_json::to_string(&results)?;

json_file.write_all(serde_data.as_bytes())?;
for log_data in results.iter() {
let serde_data = serde_json::to_string(log_data)?;
json_file.write_all(serde_data.as_bytes())?;
json_file.write_all(b"\n")?; // Add a newline after each JSON entry
}

Ok(())
}

0 comments on commit f6c495d

Please sign in to comment.