From 666d088b266db7bafeee0fac56cfa17ef12b3aaf Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Sun, 1 Aug 2021 22:01:33 +0200 Subject: [PATCH] Including tracing setup in all examples (#79) --- README.md | 3 +++ examples/error_handling_and_dependency_injection.rs | 2 ++ examples/form.rs | 2 ++ examples/hello_world.rs | 2 ++ examples/sessions.rs | 2 ++ examples/templates.rs | 2 ++ examples/tls_rustls.rs | 2 ++ examples/tokio_postgres.rs | 2 ++ examples/unix_domain_socket.rs | 2 ++ examples/versioning.rs | 2 ++ 10 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 3f79b894..15d3fd25 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,9 @@ use std::net::SocketAddr; #[tokio::main] async fn main() { + // initialize tracing + tracing_subscriber::fmt::init(); + // build our application with a route let app = // `GET /` goes to `root` diff --git a/examples/error_handling_and_dependency_injection.rs b/examples/error_handling_and_dependency_injection.rs index 07706516..fb42e336 100644 --- a/examples/error_handling_and_dependency_injection.rs +++ b/examples/error_handling_and_dependency_injection.rs @@ -18,6 +18,8 @@ use uuid::Uuid; #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + // Inject a `UserRepo` into our handlers via a trait object. This could be // the live implementation or just a mock for testing. let user_repo = Arc::new(ExampleUserRepo) as DynUserRepo; diff --git a/examples/form.rs b/examples/form.rs index a6b6346f..af93e3e8 100644 --- a/examples/form.rs +++ b/examples/form.rs @@ -4,6 +4,8 @@ use std::net::SocketAddr; #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + // build our application with some routes let app = route("/", get(show_form).post(accept_form)); diff --git a/examples/hello_world.rs b/examples/hello_world.rs index ac4cd888..08f1bc5e 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -3,6 +3,8 @@ use std::net::SocketAddr; #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + // build our application with a route let app = route("/", get(handler)); diff --git a/examples/sessions.rs b/examples/sessions.rs index 2843cbe2..6677b939 100644 --- a/examples/sessions.rs +++ b/examples/sessions.rs @@ -14,6 +14,8 @@ use uuid::Uuid; #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + // `MemoryStore` just used as an example. Don't use this in production. let store = MemoryStore::new(); diff --git a/examples/templates.rs b/examples/templates.rs index 096ade9c..5a42e4b4 100644 --- a/examples/templates.rs +++ b/examples/templates.rs @@ -5,6 +5,8 @@ use std::net::SocketAddr; #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + // build our application with some routes let app = route("/greet/:name", get(greet)); diff --git a/examples/tls_rustls.rs b/examples/tls_rustls.rs index 78085af4..833012a9 100644 --- a/examples/tls_rustls.rs +++ b/examples/tls_rustls.rs @@ -11,6 +11,8 @@ use tokio_rustls::{ #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + let rustls_config = rustls_server_config( "examples/self_signed_certs/key.pem", "examples/self_signed_certs/cert.pem", diff --git a/examples/tokio_postgres.rs b/examples/tokio_postgres.rs index 25d8a80e..9a807ab5 100644 --- a/examples/tokio_postgres.rs +++ b/examples/tokio_postgres.rs @@ -7,6 +7,8 @@ use tokio_postgres::NoTls; #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + // setup connection pool let manager = PostgresConnectionManager::new_from_stringlike("host=localhost user=postgres", NoTls) diff --git a/examples/unix_domain_socket.rs b/examples/unix_domain_socket.rs index 9077d011..4a1520f2 100644 --- a/examples/unix_domain_socket.rs +++ b/examples/unix_domain_socket.rs @@ -30,6 +30,8 @@ fn main() { #[cfg(unix)] #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + let path = PathBuf::from("/tmp/axum/helloworld"); let _ = tokio::fs::remove_file(&path).await; diff --git a/examples/versioning.rs b/examples/versioning.rs index 61fd5051..ca37498b 100644 --- a/examples/versioning.rs +++ b/examples/versioning.rs @@ -10,6 +10,8 @@ use std::net::SocketAddr; #[tokio::main] async fn main() { + tracing_subscriber::fmt::init(); + // build our application with some routes let app = route("/:version/foo", get(handler));