diff --git a/Cargo.lock b/Cargo.lock index 69b7e32..322de23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -284,6 +284,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi 0.1.19", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -615,6 +626,19 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_logger" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -877,6 +901,15 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hermit-abi" version = "0.3.3" @@ -950,6 +983,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "0.14.27" @@ -1304,7 +1343,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.3", "libc", ] @@ -2229,6 +2268,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "termcolor" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.49" @@ -2616,6 +2664,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2723,6 +2780,7 @@ dependencies = [ "actix-web", "chrono", "config", + "env_logger", "reqwest", "serde", "sqlx", diff --git a/Cargo.toml b/Cargo.toml index ddf0844..89c0e26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ name = "zero2prod" actix-web = "4" chrono = { version = "0.4.22", default-features = false, features = ["clock"] } config = "0.13" +env_logger = "0.9" serde = { version = "1", features = ["derive"] } tokio = { version = "1", features = ["macros", "rt-multi-thread"] } uuid = { version = "1", features = ["v4"] } diff --git a/src/main.rs b/src/main.rs index 384f4fb..33b6138 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,12 @@ +use env_logger::Env; use sqlx::PgPool; use std::net::TcpListener; use zero2prod::{configuration::get_configuration, startup::run}; #[tokio::main] async fn main() -> Result<(), std::io::Error> { + env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); + let configuration = get_configuration().expect("Failed to read configuration."); let connection_pool = PgPool::connect(&configuration.database.connection_string()) .await diff --git a/src/startup.rs b/src/startup.rs index 3f70691..60700cd 100644 --- a/src/startup.rs +++ b/src/startup.rs @@ -1,5 +1,5 @@ use crate::routes::{health_check, subscribe}; -use actix_web::{dev::Server, web, App, HttpServer}; +use actix_web::{dev::Server, middleware::Logger, web, App, HttpServer}; use sqlx::PgPool; use std::net::TcpListener; @@ -7,6 +7,7 @@ pub fn run(listener: TcpListener, db_pool: PgPool) -> Result