diff --git a/src-tauri/src/bin/proxy_server.rs b/src-tauri/src/bin/proxy_server.rs index 26651bc..64f6298 100644 --- a/src-tauri/src/bin/proxy_server.rs +++ b/src-tauri/src/bin/proxy_server.rs @@ -82,9 +82,14 @@ fn build_proxy_url( #[tokio::main(flavor = "multi_thread")] async fn main() { - // Initialize logger to write to stderr (which will be redirected to file) + // Initialize logger to write to stderr (which will be redirected to file). + // + // Default filter is Info — Debug pulls in reqwest/hyper internals which + // make the per-worker log unreadable on a busy browser session and obscure + // the actual lines we care about (binds, accept errors, upstream failures). + // RUST_LOG=debug or RUST_LOG=donut_proxy=trace still works for deep dives. env_logger::Builder::from_default_env() - .filter_level(log::LevelFilter::Debug) + .filter_level(log::LevelFilter::Info) .format_timestamp_millis() .init(); @@ -343,8 +348,11 @@ async fn main() { // Set high priority so this process is killed last under resource pressure set_high_priority(); - log::error!("Proxy worker starting, looking for config id: {}", id); - log::error!("Process PID: {}", std::process::id()); + log::info!( + "Proxy worker starting (pid {}, config id {})", + std::process::id(), + id + ); // Retry config loading to handle file system race condition on Windows // where the config file may not be immediately visible after being written @@ -352,7 +360,7 @@ async fn main() { let mut attempts = 0; loop { if let Some(config) = get_proxy_config(id) { - log::error!( + log::info!( "Found config: id={}, port={:?}, upstream={}", config.id, config.local_port, @@ -369,20 +377,19 @@ async fn main() { ); process::exit(1); } - log::error!("Config {} not found yet, retrying ({}/10)...", id, attempts); + log::debug!("Config {} not found yet, retrying ({}/10)...", id, attempts); std::thread::sleep(std::time::Duration::from_millis(50)); } }; // Run the proxy server - this should never return (infinite loop) - log::error!("Starting proxy server for config id: {}", id); + log::info!("Starting proxy server for config id: {}", id); if let Err(e) = run_proxy_server(config).await { - log::error!("Failed to run proxy server: {}", e); - log::error!("Error details: {:?}", e); + log::error!("Proxy server failed: {} ({:?})", e, e); process::exit(1); } // This should never be reached - run_proxy_server has an infinite loop - log::error!("ERROR: Proxy server returned unexpectedly (this should never happen)"); + log::error!("Proxy server returned unexpectedly (this should never happen)"); process::exit(1); } else { log::error!("Invalid action for proxy-worker. Use 'start'"); diff --git a/src-tauri/src/proxy_server.rs b/src-tauri/src/proxy_server.rs index 6388de6..cfe56b3 100644 --- a/src-tauri/src/proxy_server.rs +++ b/src-tauri/src/proxy_server.rs @@ -918,8 +918,8 @@ async fn handle_http( return Ok(response); } - log::error!( - "DEBUG: Handling HTTP request: {} {} (host: {:?})", + log::trace!( + "Handling HTTP request: {} {} (host: {:?})", req.method(), req.uri(), req.uri().host() @@ -1182,7 +1182,7 @@ pub async fn handle_proxy_connection( } pub async fn run_proxy_server(config: ProxyConfig) -> Result<(), Box> { - log::error!( + log::info!( "Proxy worker starting, looking for config id: {}", config.id ); @@ -1196,7 +1196,7 @@ pub async fn run_proxy_server(config: ProxyConfig) -> Result<(), Box Result<(), Box Result<(), Box Result<(), Box { - log::error!("DEBUG: Tunneled {} bytes from client->target", bytes); + log::trace!("Tunneled {bytes} bytes from client->target"); } Err(e) => { - log::error!("Error forwarding client->target: {:?}", e); + log::debug!("Error forwarding client->target: {e:?}"); } } }); @@ -1659,10 +1635,10 @@ async fn handle_connect_from_buffer( let result = tokio::io::copy(&mut target_read, &mut client_write).await; match result { Ok(bytes) => { - log::error!("DEBUG: Tunneled {} bytes from target->client", bytes); + log::trace!("Tunneled {bytes} bytes from target->client"); } Err(e) => { - log::error!("Error forwarding target->client: {:?}", e); + log::debug!("Error forwarding target->client: {e:?}"); } } }); @@ -1670,10 +1646,10 @@ async fn handle_connect_from_buffer( // Wait for either direction to finish (connection closed) tokio::select! { _ = client_to_target => { - log::error!("DEBUG: Client->target tunnel closed"); + log::trace!("Client->target tunnel closed"); } _ = target_to_client => { - log::error!("DEBUG: Target->client tunnel closed"); + log::trace!("Target->client tunnel closed"); } } @@ -1682,11 +1658,7 @@ async fn handle_connect_from_buffer( client_read_counter.load(Ordering::Relaxed) + target_write_counter.load(Ordering::Relaxed); let final_recv = target_read_counter.load(Ordering::Relaxed) + client_write_counter.load(Ordering::Relaxed); - log::error!( - "DEBUG: Tunnel closed - sent: {} bytes, received: {} bytes", - final_sent, - final_recv - ); + log::trace!("Tunnel closed - sent: {final_sent} bytes, received: {final_recv} bytes"); // Update domain-specific byte counts now that tunnel is complete if let Some(tracker) = get_traffic_tracker() {