Skip to content

Commit

Permalink
Add log crate to the server
Browse files Browse the repository at this point in the history
  • Loading branch information
ssantos21 committed Aug 12, 2024
1 parent 6ff4790 commit d80d0e8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
50 changes: 44 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 15 additions & 5 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d80d0e8

Please sign in to comment.