diff --git a/Cargo.lock b/Cargo.lock index c07ffb9..147d83b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,6 +71,15 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -717,6 +726,19 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "env_logger" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "erased-serde" version = "0.4.5" @@ -1114,6 +1136,12 @@ version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" +[[package]] +name = "humantime" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f" + [[package]] name = "iana-time-zone" version = "0.1.61" @@ -1313,6 +1341,17 @@ dependencies = [ "libc", ] +[[package]] +name = "is-terminal" +version = "0.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" +dependencies = [ + "hermit-abi 0.5.2", + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "itoa" version = "1.0.11" @@ -1795,6 +1834,35 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "regex" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" + [[package]] name = "route-recognizer" version = "0.2.0" @@ -1866,9 +1934,10 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sdk_storage" -version = "0.1.0" +version = "0.2.2" dependencies = [ "async-std", + "env_logger", "hex", "serde", "serde_json", @@ -2270,6 +2339,15 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.69" @@ -2619,6 +2697,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0978bf7171b3d90bac376700cb56d606feb40f251a475a5d6634613564460b22" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 12cfdae..487f33a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ async-std = { version = "1", features = ["attributes"] } serde = { version = "1", features = ["derive"] } serde_json = "1" hex = "0.4" +env_logger = "0.10" [dev-dependencies] tempfile = "3" diff --git a/src/lib.rs b/src/lib.rs index 3973535..a84f7f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ use async_std::path::Path; use async_std::stream::StreamExt; use serde::{Deserialize, Serialize}; use std::time::{Duration, SystemTime, UNIX_EPOCH}; -use tide::{StatusCode, Request, Response}; +use tide::{log, Request, Response, StatusCode}; #[derive(Clone, Debug)] pub struct StorageService { @@ -143,7 +143,7 @@ pub fn unix_to_system_time(unix_timestamp: u64) -> SystemTime { UNIX_EPOCH + Duration::from_secs(unix_timestamp) } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] pub struct StoreRequest { pub key: String, pub value: String, @@ -213,6 +213,8 @@ pub async fn handle_store(mut req: Request, no_ttl_permanent: bo } }; + log::info!("received {} bytes", value_bytes.len()); + let svc = req.state(); match svc.store_data(&data.key, &value_bytes, expires_at).await { Ok(()) => Ok(Response::builder(StatusCode::Ok) diff --git a/src/main.rs b/src/main.rs index 94bf171..c597cde 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use std::env; use async_std::task; use async_std::fs::create_dir_all; use sdk_storage::{StorageService, create_app}; +use tide::log; const STORAGE_DIR: &str = "./storage"; const PORT: u16 = 8081; @@ -10,6 +11,9 @@ const DEFAULT_TTL: u64 = 86400; #[async_std::main] async fn main() -> tide::Result<()> { + // Initialize logging + env_logger::init(); + log::info!("Starting server"); // Parse command line arguments let args: Vec = env::args().collect(); let no_ttl_permanent = args.iter().any(|arg| arg == "--permanent");