diff --git a/Cargo.lock b/Cargo.lock index a8a6b79..bfefbbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "actix" version = "0.10.0" @@ -125,6 +127,7 @@ dependencies = [ "actix-web", "actix-web-actors", "derive_more", + "env_logger", "serde", "serde_json", "uuid", @@ -361,6 +364,17 @@ dependencies = [ "syn", ] +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.9", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -615,6 +629,19 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "flate2" version = "1.0.20" @@ -858,6 +885,12 @@ version = "1.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "idna" version = "0.2.2" @@ -1511,6 +1544,15 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.24" @@ -1873,6 +1915,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 8c765e0..6eea767 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ uuid = { version = "0.8", features = ["serde", "v4"] } derive_more = "0.99.11" serde_json = "1.0.64" serde = "1.0.124" +env_logger = "0.8.3" \ No newline at end of file diff --git a/README.md b/README.md index e1d0d1b..27ae5a6 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ To execute any operation you have to send a json which has the following format: ```json { - "ty": "Create" | "Join" | "Leave" | "Msg", - "data": "" + "ty": "", + "data": "" } ``` @@ -46,7 +46,7 @@ To execute any operation you have to send a json which has the following format: ```json { "ty": "Info", - "data": + "data": "" } ``` @@ -54,7 +54,7 @@ To execute any operation you have to send a json which has the following format: ```json { "ty": "Join", - "data": + "data": "" } ``` + Response: @@ -96,7 +96,7 @@ If an error occurs, the server will send back a json with the following format: ```json { "ty": "Err", - "data" + "data": "" } ``` diff --git a/src/main.rs b/src/main.rs index c7abf80..a35c9b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ mod routes; use crate::{actors::chat_server::ChatServer, models::AppState}; use actix::Actor; -use actix_web::{App, HttpServer}; +use actix_web::{middleware, App, HttpServer}; use routes::connect; fn get_server_addr() -> String { @@ -16,10 +16,13 @@ fn get_server_addr() -> String { #[actix_web::main] async fn main() -> std::io::Result<()> { + std::env::set_var("RUST_LOG", "actix_web=info"); + env_logger::init(); let addr = get_server_addr(); let chat = ChatServer::new().start(); HttpServer::new(move || { App::new() + .wrap(middleware::Logger::default()) .data(AppState { chat: chat.clone() }) .service(connect) })