feat: allow to request remote tracing via socket

This commit is contained in:
əlemi 2023-04-12 05:00:37 +02:00
parent a872c39d7f
commit 77eae35bc3

View file

@ -212,6 +212,10 @@ struct CliArgs {
/// show debug level logs /// show debug level logs
#[arg(long, default_value_t = false)] #[arg(long, default_value_t = false)]
debug: bool, debug: bool,
/// dump raw tracing logs into this TCP host
#[arg(long)]
remote_debug: Option<String>,
} }
@ -219,22 +223,21 @@ struct CliArgs {
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = CliArgs::parse(); let args = CliArgs::parse();
let sub = tracing_subscriber::fmt(); match args.remote_debug {
match TcpStream::connect("127.0.0.1:6969") { // TODO get rid of this Some(host) =>
Ok(stream) => { tracing_subscriber::fmt()
sub.with_writer(Mutex::new(stream)) .with_writer(Mutex::new(TcpStream::connect(host)?))
.with_max_level(if args.debug { tracing::Level::DEBUG } else { tracing::Level::INFO }) .with_max_level(if args.debug { tracing::Level::DEBUG } else { tracing::Level::INFO })
.init(); .init(),
},
Err(_) => { None =>
sub tracing_subscriber::fmt()
.compact() .compact()
.without_time() .without_time()
.with_ansi(false) .with_ansi(false)
.with_writer(std::io::stderr) .with_writer(std::io::stderr)
.with_max_level(if args.debug { tracing::Level::DEBUG } else { tracing::Level::INFO }) .with_max_level(if args.debug { tracing::Level::DEBUG } else { tracing::Level::INFO })
.init(); .init(),
},
} }
let client = BufferClient::connect(args.host).await?; let client = BufferClient::connect(args.host).await?;