January 2019
Intermediate to advanced
520 pages
14h 32m
English
We can now add logging to our microservice. In the following example, we will print information about the socket address, the incoming request, and a generated random value:
fn main() { logger::init(); info!("Rand Microservice - v0.1.0"); trace!("Starting..."); let addr = ([127, 0, 0, 1], 8080).into(); debug!("Trying to bind server to address: {}", addr); let builder = Server::bind(&addr); trace!("Creating service handler..."); let server = builder.serve(|| { service_fn_ok(|req| { trace!("Incoming request is: {:?}", req); let random_byte = rand::random::<u8>(); debug!("Generated value is: {}", random_byte); Response::new(Body::from(random_byte.to_string())) }) }); info!("Used address: {}", server.local_addr()); let server = ...Read now
Unlock full access