From 6e08bea76723fceeba7fc1fd2be105232b8211d5 Mon Sep 17 00:00:00 2001 From: 0x90 <134144784+riccio8@users.noreply.github.com> Date: Mon, 23 Jun 2025 15:34:40 +0200 Subject: [PATCH 1/2] Update main.rs Add JSON-formatted logging to log.json when -l or --log flag is passed --- src/main.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 71429c4..853392b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,24 @@ use std::net::IpAddr; +use std::fs::OpenOptions; +use std::io::Write; + +use serde::Serialize; + use anyhow::Result; use bore_cli::{client::Client, server::Server}; use clap::{error::ErrorKind, CommandFactory, Parser, Subcommand}; -#[derive(Parser, Debug)] +#[derive(Parser, Debug, Serialize)] #[clap(author, version, about)] struct Args { #[clap(subcommand)] command: Command, + #[clap(short, long, default_value = "false")] + log: bool, } -#[derive(Subcommand, Debug)] +#[derive(Subcommand, Debug, Serialize)] enum Command { /// Starts a local proxy to the remote server. Local { @@ -98,5 +105,22 @@ async fn run(command: Command) -> Result<()> { fn main() -> Result<()> { tracing_subscriber::fmt::init(); - run(Args::parse().command) + + let args = Args::parse(); + + if args.log { + use serde_json::to_string_pretty; + + let json = to_string_pretty(&args.command).expect("failed to serialize command to JSON"); + + let mut file = OpenOptions::new() + .append(true) + .create(true) + .open("log.json") + .expect("could not create/open log file"); + + writeln!(file, "{}", json).expect("could not write to log file"); + } + + run(args.command) } From c605d0220a2b5d0291e6d7991472ffa7093653bc Mon Sep 17 00:00:00 2001 From: 0x90 <134144784+riccio8@users.noreply.github.com> Date: Mon, 23 Jun 2025 15:58:28 +0200 Subject: [PATCH 2/2] Update main.rs --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 853392b..96ff61b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use clap::{error::ErrorKind, CommandFactory, Parser, Subcommand}; struct Args { #[clap(subcommand)] command: Command, - #[clap(short, long, default_value = "false")] + #[clap(long)] log: bool, }