diff --git a/Cargo.lock b/Cargo.lock index a339f0cd..665fff40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,23 +107,24 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.4" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.4" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" @@ -862,6 +863,29 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -1262,6 +1286,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" @@ -1386,6 +1416,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.11.0" @@ -1522,9 +1558,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "loom" @@ -1585,7 +1621,9 @@ dependencies = [ "bitcoin", "chrono", "config", + "env_logger", "hex", + "log", "mercurylib", "rand", "reqwest", diff --git a/server/Cargo.toml b/server/Cargo.toml index e3814d91..908af0fb 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -22,3 +22,5 @@ secp256k1-zkp = { git = "https://github.com/ssantos21/rust-secp256k1-zkp.git", b mercurylib = { path = "../lib" } chrono = "0.4.31" sha2 = "0.10.8" +log = "0.4.22" +env_logger = "0.11.5" diff --git a/server/src/main.rs b/server/src/main.rs index 1a3461bc..90a4277c 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -11,24 +11,34 @@ use rocket::fairing::{Fairing, Info, Kind}; use rocket::http::Header; use server::StateChainEntity; +use log::error; + #[catch(500)] -fn internal_error() -> Value { - json!("Internal server error") +fn internal_error(req: &Request) -> Value { + let message = format!("500 - Internal Server Error: {}", req.uri()); + error!("{}", message); + json!(message) } #[catch(400)] -fn bad_request() -> Value { - json!("Bad request") +fn bad_request(req: &Request) -> Value { + let message = format!("400 - Bad request: {}", req.uri()); + error!("{}", message); + json!(message) } #[catch(404)] fn not_found(req: &Request) -> Value { - json!(format!("Not found! Unknown route '{}'.", req.uri())) + let message = format!("404 - Not Found: {}", req.uri()); + error!("{}", message); + json!(message) } #[rocket::main] async fn main() { + env_logger::init(); + server_config::ServerConfig::load(); let statechain_entity = StateChainEntity::new().await;