From 6fa4f04a0cc5639bf6efe39dfcf363fb8de70d83 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Sat, 5 Sep 2020 20:31:47 -0400 Subject: [PATCH] standardize error logs --- src/admin.rs | 12 ++++++------ src/main.rs | 8 ++++---- src/proxy.rs | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/admin.rs b/src/admin.rs index ca60f68..0f8240d 100644 --- a/src/admin.rs +++ b/src/admin.rs @@ -52,7 +52,7 @@ pub async fn start_admin (admin_port : u16, let routes = warp::post().and(register); let admin_server = warp::serve(routes).run(admin_sock); - eprintln!("Admin listening on {}", admin_sock); + eprintln!("start_admin: INFO: Admin listening on {}", admin_sock); admin_server.await; } @@ -64,7 +64,7 @@ async fn handle_register(registration : AdminRegistration, hashed_password : String) -> Result { let pass_result = is_correct_password(registration.password, hashed_password); if pass_result.is_err() { - eprintln!("handle_register: error verifying password: {:?}", pass_result.err()); + eprintln!("handle_register: ERROR: error verifying password: {:?}", pass_result.err()); Ok(warp::reply::with_status( "error verifying password", http::StatusCode::UNAUTHORIZED, @@ -93,7 +93,7 @@ async fn handle_register(registration : AdminRegistration, // PUT it and see if it worked let client = reqwest::Client::new(); let url = format!("https://{}/api/me/flexRouters", registration.bubble); - println!("handle_register: registering ourself with {}, sending: {:?}", url, bubble_registration); + println!("handle_register: INFO registering ourself with {}, sending: {:?}", url, bubble_registration); match client.put(url.as_str()) .header(HEADER_BUBBLE_SESSION, registration.session) .json(&bubble_registration) @@ -101,14 +101,14 @@ async fn handle_register(registration : AdminRegistration, Ok(response) => { match response.status() { ReqwestStatusCode::OK => { - eprintln!("successfully registered with bubble"); + eprintln!("handle_register: INFO successfully registered with bubble"); Ok(warp::reply::with_status( "successfully registered with bubble", http::StatusCode::OK, )) }, _ => { - eprintln!("error registering with bubble: {:?}", response.status()); + eprintln!("handle_register: ERROR: error registering with bubble: {:?}", response.status()); Ok(warp::reply::with_status( "error registering with bubble", http::StatusCode::PRECONDITION_FAILED, @@ -117,7 +117,7 @@ async fn handle_register(registration : AdminRegistration, } }, Err(error) => { - eprintln!("error registering with bubble: {:?}", error); + eprintln!("handle_register: ERROR: error registering with bubble: {:?}", error); Ok(warp::reply::with_status( "error registering with bubble", http::StatusCode::PRECONDITION_FAILED, diff --git a/src/main.rs b/src/main.rs index aa1b057..d159040 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,7 +84,7 @@ async fn main() { let password_file_opt = args.value_of("password_file"); if password_file_opt.is_none() { - eprintln!("\nERROR: password-file argument is required\n"); + eprintln!("\nmain: ERROR: password-file argument is required\n"); exit(2); } let password_file = password_file_opt.unwrap(); @@ -94,13 +94,13 @@ async fn main() { let proxy_ip_opt = args.value_of("proxy_ip"); if proxy_ip_opt.is_none() { - eprintln!("\nERROR: proxy-ip argument is required\n"); + eprintln!("\nmain: ERROR: proxy-ip argument is required\n"); exit(2); } let proxy_ip = proxy_ip_opt.unwrap(); if !is_private_ip(proxy_ip.to_string()) { - eprintln!("\nERROR: proxy IP must be a private IP address: {}\n", proxy_ip); + eprintln!("\nmain: ERROR: proxy IP must be a private IP address: {}\n", proxy_ip); exit(2); } let mut proxy_bind_addr = None; @@ -115,7 +115,7 @@ async fn main() { } } if proxy_bind_addr.is_none() { - eprintln!("\nERROR: Could not find IP for binding: {}\n", proxy_ip); + eprintln!("\nmain: ERROR: Could not find IP for binding: {}\n", proxy_ip); exit(2); } diff --git a/src/proxy.rs b/src/proxy.rs index da64b71..7af9fd2 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -73,9 +73,9 @@ pub async fn start_proxy (dns1_ip : &str, }); let server = Server::bind(&addr).serve(make_service); - eprintln!("Proxy listening on {}", addr); + eprintln!("start_proxy: INFO Proxy listening on {}", addr); let result = server.await; - eprintln!("Proxy await result: {:?}", result); + eprintln!("start_proxy: INFO Proxy await result: {:?}", result); } async fn proxy(client: Client>>, @@ -90,7 +90,7 @@ async fn proxy(client: Client>>, } let host = host.unwrap(); let ip_string = resolve_with_cache(host, &resolver, resolver_cache).await; - eprintln!("proxy: req(host {} resolved to: {}): {:?}", host, ip_string, req); + eprintln!("proxy: INFO req(host {} resolved to: {}): {:?}", host, ip_string, req); if needs_static_route(&ip_string) { if !create_static_route(&gateway, &ip_string) { @@ -160,7 +160,7 @@ async fn tunnel(upgraded: Upgraded, addr: SocketAddr) -> std::io::Result<()> { // Print message when done match amounts { Ok((from_client, from_server)) => { - println!("client wrote {} bytes and received {} bytes", from_client, from_server); + eprintln!("proxy: DEBUG: client wrote {} bytes and received {} bytes", from_client, from_server); } Err(e) => { eprintln!("proxy: ERROR: tunnel error: {}", e);