@@ -11,6 +11,7 @@ use parity_scale_codec::{Decode, Encode};
1111use thiserror:: Error ;
1212use tokio:: sync:: { mpsc, oneshot} ;
1313use tokio_rustls:: rustls:: server:: { VerifierBuilderError , WebPkiClientVerifier } ;
14+ use tracing:: { error, warn} ;
1415
1516#[ cfg( test) ]
1617mod test_helpers;
@@ -153,7 +154,7 @@ impl ProxyServer {
153154 )
154155 . await
155156 {
156- eprintln ! ( "Failed to handle connection: {err}" ) ;
157+ warn ! ( "Failed to handle connection: {err}" ) ;
157158 }
158159 } ) ;
159160
@@ -244,7 +245,7 @@ impl ProxyServer {
244245 Err ( e) => {
245246 // This error is highly unlikely - that the measurement values fail to
246247 // encode to JSON or fit in an HTTP header
247- eprintln ! ( "Failed to encode measurement values: {e}" ) ;
248+ error ! ( "Failed to encode measurement values: {e}" ) ;
248249 }
249250 }
250251 headers. insert (
@@ -260,7 +261,7 @@ impl ProxyServer {
260261 Ok :: < Response < BoxBody < bytes:: Bytes , hyper:: Error > > , hyper:: Error > ( res)
261262 }
262263 Err ( e) => {
263- eprintln ! ( "Failed to handle a request from a proxy-client: {e}" ) ;
264+ warn ! ( "Failed to handle a request from a proxy-client: {e}" ) ;
264265 let mut resp = Response :: new ( full ( format ! ( "Request failed: {e}" ) ) ) ;
265266 * resp. status_mut ( ) = hyper:: StatusCode :: BAD_GATEWAY ;
266267 Ok ( resp)
@@ -291,15 +292,15 @@ impl ProxyServer {
291292 // Drive the connection
292293 tokio:: spawn ( async move {
293294 if let Err ( e) = conn. await {
294- eprintln ! ( "Client connection error: {e}" ) ;
295+ warn ! ( "Client connection error: {e}" ) ;
295296 }
296297 } ) ;
297298
298299 // Forward the request from the proxy-client to the target server
299300 match sender. send_request ( req) . await {
300301 Ok ( resp) => Ok ( resp. map ( |b| b. boxed ( ) ) ) ,
301302 Err ( e) => {
302- eprintln ! ( "send_request error: {e}" ) ;
303+ warn ! ( "send_request error: {e}" ) ;
303304 let mut resp = Response :: new ( full ( format ! ( "Request failed: {e}" ) ) ) ;
304305 * resp. status_mut ( ) = hyper:: StatusCode :: BAD_GATEWAY ;
305306 Ok ( resp)
@@ -428,7 +429,7 @@ impl ProxyClient {
428429 Err ( e) => {
429430 // This error is highly unlikely - that the measurement values fail to
430431 // encode to JSON or fit in an HTTP header
431- eprintln ! ( "Failed to encode measurement values: {e}" ) ;
432+ error ! ( "Failed to encode measurement values: {e}" ) ;
432433 }
433434 }
434435 headers. insert (
@@ -440,7 +441,7 @@ impl ProxyClient {
440441 ( Ok ( resp. map ( |b| b. boxed ( ) ) ) , false )
441442 }
442443 Err ( e) => {
443- eprintln ! ( "Failed to send request to proxy-server: {e}" ) ;
444+ warn ! ( "Failed to send request to proxy-server: {e}" ) ;
444445 let mut resp = Response :: new ( full ( format ! ( "Request failed: {e}" ) ) ) ;
445446 * resp. status_mut ( ) = hyper:: StatusCode :: BAD_GATEWAY ;
446447
@@ -450,7 +451,7 @@ impl ProxyClient {
450451
451452 // Send the response back to the source client
452453 if response_tx. send ( response) . is_err ( ) {
453- eprintln ! ( "Failed to forward response to source client, probably they dropped the connection" ) ;
454+ warn ! ( "Failed to forward response to source client, probably they dropped the connection" ) ;
454455 }
455456
456457 // If the connection to the proxy server failed, reconnect
@@ -488,7 +489,7 @@ impl ProxyClient {
488489
489490 tokio:: spawn ( async move {
490491 if let Err ( err) = Self :: handle_connection ( inbound, requests_tx) . await {
491- eprintln ! ( "Failed to handle connection from source client: {err}" ) ;
492+ warn ! ( "Failed to handle connection from source client: {err}" ) ;
492493 }
493494 } ) ;
494495
@@ -510,7 +511,7 @@ impl ProxyClient {
510511 Ok :: < Response < BoxBody < bytes:: Bytes , hyper:: Error > > , hyper:: Error > ( res)
511512 }
512513 Err ( e) => {
513- eprintln ! ( "send_request error: {e}" ) ;
514+ warn ! ( "send_request error: {e}" ) ;
514515 let mut resp = Response :: new ( full ( format ! ( "Request failed: {e}" ) ) ) ;
515516 * resp. status_mut ( ) = hyper:: StatusCode :: BAD_GATEWAY ;
516517 Ok ( resp)
@@ -551,7 +552,7 @@ impl ProxyClient {
551552 return output;
552553 }
553554 Err ( e) => {
554- eprintln ! ( "Reconnect failed: {e}. Retrying in {:#?}..." , delay) ;
555+ warn ! ( "Reconnect failed: {e}. Retrying in {:#?}..." , delay) ;
555556 tokio:: time:: sleep ( delay) . await ;
556557
557558 // increase delay for next time (exponential), but clamp to max_delay
@@ -634,7 +635,7 @@ impl ProxyClient {
634635 // Drive the connection
635636 tokio:: spawn ( async move {
636637 if let Err ( e) = conn. await {
637- eprintln ! ( "Client connection error: {e}" ) ;
638+ warn ! ( "Client connection error: {e}" ) ;
638639 }
639640 } ) ;
640641
0 commit comments