From 27ff3d00bd770e2ebe2e42acc28356ac5b8efaad Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Tue, 30 Jan 2024 17:04:42 +0000 Subject: add tracing --- Cargo.lock | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/main.rs | 7 +++++++ 3 files changed, 78 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a86ee13..3fff1c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,6 +211,8 @@ dependencies = [ "tokio", "tokio-stream", "toml", + "tracing", + "tracing-subscriber", ] [[package]] @@ -1274,6 +1276,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-traits" version = "0.2.17" @@ -1352,6 +1364,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking_lot" version = "0.12.1" @@ -1882,6 +1900,15 @@ dependencies = [ "digest", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -2138,6 +2165,16 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "time" version = "0.3.31" @@ -2336,6 +2373,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", ] [[package]] @@ -2454,6 +2517,12 @@ dependencies = [ "getrandom", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "value-bag" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index 25f0664..3147ef5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,5 @@ askama_poem = { git = "https://bunny.garden/forks/askama.git" } rust-embed = "8.2.0" rand = "0.8.5" thiserror = "1.0.56" +tracing = "0.1.40" +tracing-subscriber = "0.3.18" diff --git a/src/main.rs b/src/main.rs index 25bc21f..de9b7ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,7 @@ use poem::{ get, handler, listener::TcpListener, middleware::AddData, + middleware::Tracing, web::{Data, Path, Query}, EndpointExt, Route, Server, }; @@ -25,6 +26,7 @@ use rust_embed::RustEmbed; use error::BlossomError; use serde::Deserialize; +use tracing_subscriber::FmtSubscriber; type Result = std::result::Result; @@ -124,8 +126,12 @@ async fn custom_error(err: poem::Error) -> impl IntoResponse { #[tokio::main] async fn main() -> std::result::Result<(), std::io::Error> { + let subscriber = FmtSubscriber::new(); + tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); + // let mut skinny_data = mastodon_async::Data::default(); // skinny_data.base = Cow::from("https://skinnyver.se"); + let blossom = Route::new() .at("/", get(home)) .at("/blog", get(get_blog)) @@ -135,6 +141,7 @@ async fn main() -> std::result::Result<(), std::io::Error> { .at("/plants", get(plants)) .nest("/static/", EmbeddedFilesEndpoint::::new()) .catch_all_error(custom_error) + .with(Tracing) .with(AddData::new( reqwest::Client::builder() .connect_timeout(Duration::from_secs(1)) -- cgit