From 1b99dd20ca5a4b8988da310ad36d4e6678022848 Mon Sep 17 00:00:00 2001 From: Sam Nystrom Date: Thu, 2 Nov 2023 19:56:38 -0400 Subject: [PATCH] feat: remove tracing We don't need very advanced logging and instrumentation. BREAKING CHANGE: Remove feature "tracing" from mp4-stream crate --- Cargo.lock | 150 +++++++----------- Cargo.toml | 8 +- crates/mp4-stream/Cargo.toml | 2 +- crates/mp4-stream/src/capabilities.rs | 6 - crates/mp4-stream/src/lib.rs | 57 +++---- crates/pet-monitor-app/Cargo.toml | 6 +- .../src/bin/pet-monitor-app/main.rs | 17 +- crates/pet-monitor-app/src/config.rs | 8 +- crates/pet-monitor-app/src/handlers.rs | 17 +- crates/pet-monitor-app/src/lib.rs | 9 +- 10 files changed, 99 insertions(+), 181 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9774d518..137a7bc9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -493,6 +493,19 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -744,6 +757,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "hermit-abi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" + [[package]] name = "hex" version = "0.4.3" @@ -799,6 +818,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" @@ -917,6 +942,17 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + [[package]] name = "itoa" version = "1.0.9" @@ -996,15 +1032,6 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata 0.1.10", -] - [[package]] name = "matchit" version = "0.7.3" @@ -1059,10 +1086,10 @@ dependencies = [ "fixed", "flume", "futures-lite", + "log", "quick-error", "rscam", "serde", - "tracing", "x264", ] @@ -1085,16 +1112,6 @@ 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-bigint" version = "0.4.4" @@ -1146,12 +1163,6 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - [[package]] name = "owo-colors" version = "3.5.0" @@ -1216,11 +1227,13 @@ dependencies = [ "axum-macros", "color-eyre", "confy", + "env_logger", "flume", "futures-lite", "hyper", "include_dir", "jsonwebtoken", + "log", "mp4-stream", "percent-encoding", "ring 0.16.20", @@ -1236,10 +1249,6 @@ dependencies = [ "tower", "tower-cookies", "tower-http", - "tracing", - "tracing-error", - "tracing-subscriber", - "tracing-tree", "ureq", "xflags", ] @@ -1368,17 +1377,8 @@ checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.3", - "regex-syntax 0.8.2", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax 0.6.29", + "regex-automata", + "regex-syntax", ] [[package]] @@ -1389,15 +1389,9 @@ checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.2", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - [[package]] name = "regex-syntax" version = "0.8.2" @@ -1774,6 +1768,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "termcolor" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +dependencies = [ + "winapi-util", +] + [[package]] name = "termion" version = "2.0.1" @@ -2016,21 +2019,9 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite", - "tracing-attributes", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tracing-core" version = "0.1.32" @@ -2051,45 +2042,15 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "tracing-log" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - [[package]] name = "tracing-subscriber" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" dependencies = [ - "matchers", - "nu-ansi-term", - "once_cell", - "regex", "sharded-slab", - "smallvec", "thread_local", - "tracing", - "tracing-core", - "tracing-log", -] - -[[package]] -name = "tracing-tree" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ec6adcab41b1391b08a308cc6302b79f8095d1673f6947c2dc65ffb028b0b2d" -dependencies = [ - "nu-ansi-term", "tracing-core", - "tracing-log", - "tracing-subscriber", ] [[package]] @@ -2301,6 +2262,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index b0ebc5d1..9f987836 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,10 +20,8 @@ hyper = "0.14" tokio = { version = "1.30", features = ["rt", "macros", "fs", "io-util"] } futures-lite = "1.13" flume = "0.10" -tracing = "0.1" -tracing-subscriber = { version = "0.3", features = ["env-filter"] } -tracing-tree = "0.2" -tracing-error = "0.2" +log = "0.4" +env_logger = "0.10" include_dir = "0.7" xflags = "0.3" confy = "0.5" @@ -37,7 +35,7 @@ tower-cookies = "0.9" ring = "0.16" jsonwebtoken = "8.3" rust-argon2 = "1.0" -mp4-stream = { path = "crates/mp4-stream", features = ["serde", "tracing"] } +mp4-stream = { path = "crates/mp4-stream", features = ["serde", "log"] } quick-error = "2.0" serde = { version = "1.0", features = ["derive"] } chrono = "0.4" diff --git a/crates/mp4-stream/Cargo.toml b/crates/mp4-stream/Cargo.toml index 5c608720..8a0267ee 100644 --- a/crates/mp4-stream/Cargo.toml +++ b/crates/mp4-stream/Cargo.toml @@ -16,8 +16,8 @@ license.workspace = true [dependencies] flume.workspace = true quick-error.workspace = true -tracing = { workspace = true, optional = true } serde = { workspace = true, optional = true } +log = { workspace = true, optional = true } chrono.workspace = true bitflags.workspace = true fixed.workspace = true diff --git a/crates/mp4-stream/src/capabilities.rs b/crates/mp4-stream/src/capabilities.rs index cc365333..54585ba2 100644 --- a/crates/mp4-stream/src/capabilities.rs +++ b/crates/mp4-stream/src/capabilities.rs @@ -119,7 +119,6 @@ struct Resolution { /// /// This function may return a [`Error::Io`] if interaction with the filesystem /// fails or a [`Error::Camera`] if the camera returns an error. -#[cfg_attr(feature = "tracing", tracing::instrument(level = "debug"))] pub fn get_capabilities_all() -> crate::Result { let mut caps = HashMap::new(); @@ -147,7 +146,6 @@ pub fn get_capabilities_all() -> crate::Result { /// /// This function may return a [`Error::Io`] if interaction with the filesystem /// fails or a [`Error::Camera`] if the camera returns an error. -#[cfg_attr(feature = "tracing", tracing::instrument(level = "debug"))] pub fn get_capabilities_from_path(device: &Path) -> crate::Result { let camera = rscam::Camera::new( device @@ -157,7 +155,6 @@ pub fn get_capabilities_from_path(device: &Path) -> crate::Result { get_capabilities(&camera) } -#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip_all))] fn get_capabilities(camera: &rscam::Camera) -> crate::Result { camera .formats() @@ -183,7 +180,6 @@ fn get_capabilities(camera: &rscam::Camera) -> crate::Result { .collect() } -#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace"))] fn get_resolutions(resolutions: ResolutionInfo) -> Vec<(u32, u32)> { match resolutions { ResolutionInfo::Discretes(r) => r, @@ -194,7 +190,6 @@ fn get_resolutions(resolutions: ResolutionInfo) -> Vec<(u32, u32)> { } } -#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace"))] fn get_intervals(intervals: IntervalInfo) -> Vec<(u32, u32)> { match intervals { IntervalInfo::Discretes(r) => r, @@ -213,7 +208,6 @@ fn get_intervals(intervals: IntervalInfo) -> Vec<(u32, u32)> { /// /// This function may return a [`Error::Other`] if any part of the config is invalid, /// including the V4L2 controls. -#[cfg_attr(feature = "tracing", tracing::instrument(level = "debug", skip(caps)))] pub fn check_config(config: &Config, caps: &Capabilities) -> crate::Result<()> { caps.0 .get(&config.device) diff --git a/crates/mp4-stream/src/lib.rs b/crates/mp4-stream/src/lib.rs index d998ae77..b88c3f86 100644 --- a/crates/mp4-stream/src/lib.rs +++ b/crates/mp4-stream/src/lib.rs @@ -41,7 +41,6 @@ //! [`config`] module. //! - `serde`: Add implementations of [`Serialize`](serde::Serialize) and [`Deserialize`](serde::Deserialize) //! for types in the [`config`] and [`capabilities`] modules. -//! - `tracing`: Enable logging and instrumentation with the [`tracing`] crate. #![warn(clippy::unwrap_used)] #![warn(clippy::expect_used)] @@ -266,10 +265,6 @@ pub struct MediaSegment { } impl MediaSegment { - #[cfg_attr( - feature = "tracing", - tracing::instrument(level = "trace", skip(sample_sizes, data)) - )] fn new(config: &Config, sequence_number: u32, sample_sizes: Vec, data: Vec) -> Self { let timescale = config.interval.1; let mut moof = MovieFragmentBox { @@ -348,10 +343,6 @@ impl WriteTo for MediaSegment { /// This function may return an [`Error::Other`] if all receivers on /// `stream_sub_tx` have ben dropped. #[allow(clippy::missing_panics_doc)] -#[cfg_attr( - feature = "tracing", - tracing::instrument(level = "debug", skip(stream_sub_tx)) -)] pub async fn stream( config: &Config, stream_sub_tx: flume::Sender, @@ -390,8 +381,8 @@ pub async fn stream( } let Some(mut segment) = state.segment_stream.next().await else { - #[cfg(feature = "tracing")] - tracing::trace!("VideoStream ended"); + #[cfg(feature = "log")] + log::trace!("VideoStream ended"); return Ok(None); }; @@ -407,8 +398,8 @@ pub async fn stream( let mut buf = Vec::with_capacity(size as usize); segment.write_to(&mut buf)?; - #[cfg(feature = "tracing")] - tracing::trace!( + #[cfg(feature = "log")] + log::trace!( "VideoStream sent media segment with sequence number {}", state.sequence_number - 1 ); @@ -422,7 +413,6 @@ struct FrameIter { } impl FrameIter { - #[cfg_attr(feature = "tracing", tracing::instrument(level = "trace"))] fn new(config: &Config) -> Result { let mut camera = Camera::new( config @@ -442,8 +432,8 @@ impl FrameIter { if let Some(id) = controls.get(name) { camera.set_control(*id, val).unwrap_or(()); // ignore failure } else { - #[cfg(feature = "tracing")] - tracing::warn!("Couldn't find control {}", name); + #[cfg(feature = "log")] + log::warn!("Couldn't find control {}", name); } } @@ -481,10 +471,6 @@ enum SegmentIter { } impl SegmentIter { - #[cfg_attr( - feature = "tracing", - tracing::instrument(level = "trace", skip(frames)) - )] fn new(config: Config, frames: FrameIter) -> x264::Result { Ok(match config.format { Format::H264 => Self::Hardware { frames, config }, @@ -534,7 +520,6 @@ impl SegmentIter { impl Iterator for SegmentIter { type Item = Result; - #[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip_all))] fn next(&mut self) -> Option { match self { Self::Software { @@ -551,8 +536,8 @@ impl Iterator for SegmentIter { let frame = match frames.next() { Some(Ok(f)) => f, Some(Err(e)) => { - #[cfg(feature = "tracing")] - tracing::warn!("Capturing frame failed with error {:?}", e); + #[cfg(feature = "log")] + log::warn!("Capturing frame failed with error {:?}", e); return Some(Err(e.into())); } None => unreachable!(), @@ -571,8 +556,8 @@ impl Iterator for SegmentIter { let (data, _) = match encoder.encode(*timestamp, image) { Ok(x) => x, Err(e) => { - #[cfg(feature = "tracing")] - tracing::warn!("Encoding frame failed with error {:?}", e); + #[cfg(feature = "log")] + log::warn!("Encoding frame failed with error {:?}", e); return Some(Err(e.into())); } }; @@ -592,8 +577,8 @@ impl Iterator for SegmentIter { let frame = match frames.next() { Some(Ok(f)) => f, Some(Err(e)) => { - #[cfg(feature = "tracing")] - tracing::warn!("Capturing frame failed with error {:?}", e); + #[cfg(feature = "log")] + log::warn!("Capturing frame failed with error {:?}", e); return Some(Err(e.into())); } None => unreachable!(), @@ -634,18 +619,14 @@ pub type StreamSubscriber = flume::Sender<(Vec, MediaSegReceiver)>; /// device fails, an [`Error::Other`] if the device path is invalid UTF-8, or an /// [`Error::Encoding`] if constructing an encoder fails. #[allow(clippy::missing_panics_doc)] -#[cfg_attr( - feature = "tracing", - tracing::instrument(level = "debug", skip(rx, config_rx)) -)] pub fn stream_media_segments( rx: flume::Receiver, mut config: Config, config_rx: Option>, ) -> Result { 'main: loop { - #[cfg(feature = "tracing")] - tracing::trace!("Starting stream with config {:?}", config); + #[cfg(feature = "log")] + log::trace!("Starting stream with config {:?}", config); let mut senders: Vec> = Vec::new(); let frames = FrameIter::new(&config)?; @@ -656,8 +637,8 @@ pub fn stream_media_segments( if let Some(Ok(new_config)) = config_rx.as_ref().map(flume::Receiver::try_recv) { config = new_config; senders.clear(); - #[cfg(feature = "tracing")] - tracing::trace!("Config updated to {:?}, restarting stream", config); + #[cfg(feature = "log")] + log::trace!("Config updated to {:?}, restarting stream", config); continue 'main; } if let Ok(sender) = rx.try_recv() { @@ -666,15 +647,15 @@ pub fn stream_media_segments( sender.send((headers.clone(), rx)).unwrap_or(()); } - #[cfg(feature = "tracing")] + #[cfg(feature = "log")] let time = std::time::Instant::now(); #[allow(clippy::unwrap_used)] // the iterator never returns `None` let Ok(media_segment) = segments.next().unwrap() else { break; }; senders.retain(|sender| sender.send(media_segment.clone()).is_ok()); - #[cfg(feature = "tracing")] - tracing::trace!("Sent media segment, took {:?} to capture", time.elapsed()); + #[cfg(feature = "log")] + log::trace!("Sent media segment, took {:?} to capture", time.elapsed()); } } } diff --git a/crates/pet-monitor-app/Cargo.toml b/crates/pet-monitor-app/Cargo.toml index 3fdc62a0..749df407 100644 --- a/crates/pet-monitor-app/Cargo.toml +++ b/crates/pet-monitor-app/Cargo.toml @@ -22,10 +22,8 @@ hyper.workspace = true tokio.workspace = true futures-lite.workspace = true flume.workspace = true -tracing.workspace = true -tracing-subscriber.workspace = true -tracing-tree.workspace = true -tracing-error.workspace = true +log.workspace = true +env_logger.workspace = true include_dir.workspace = true xflags.workspace = true confy.workspace = true diff --git a/crates/pet-monitor-app/src/bin/pet-monitor-app/main.rs b/crates/pet-monitor-app/src/bin/pet-monitor-app/main.rs index 31b32f68..d913921f 100644 --- a/crates/pet-monitor-app/src/bin/pet-monitor-app/main.rs +++ b/crates/pet-monitor-app/src/bin/pet-monitor-app/main.rs @@ -13,9 +13,6 @@ use std::{ }; use termion::input::TermRead; use tokio::task::spawn_blocking; -use tracing_error::ErrorLayer; -use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry}; -use tracing_tree::HierarchicalLayer; #[cfg(not(test))] const ARGON2_CONFIG: argon2::Config = argon2::Config { @@ -45,8 +42,6 @@ const ARGON2_CONFIG: argon2::Config = argon2::Config { #[tokio::main(flavor = "current_thread")] async fn main() -> eyre::Result<()> { - color_eyre::install()?; - xflags::xflags! { /// A simple and secure pet monitor for Linux cmd pet-monitor-app { @@ -76,16 +71,8 @@ async fn main() -> eyre::Result<()> { return Ok(()); } - Registry::default() - .with(EnvFilter::from_default_env()) - .with( - HierarchicalLayer::new(2) - .with_ansi(true) - .with_targets(true) - .with_bracketed_fields(true), - ) - .with(ErrorLayer::default()) - .init(); + color_eyre::install()?; + env_logger::init(); let rng = SystemRandom::new(); diff --git a/crates/pet-monitor-app/src/config.rs b/crates/pet-monitor-app/src/config.rs index 8b3ba461..9268f473 100644 --- a/crates/pet-monitor-app/src/config.rs +++ b/crates/pet-monitor-app/src/config.rs @@ -81,12 +81,12 @@ impl Default for Context { pub async fn store(path: Option, ctx: Context) -> eyre::Result<()> { spawn_blocking(move || match path { Some(path) => confy::store_path(&path, ctx.clone()).or_else(|e| { - tracing::warn!("Writing config failed: {e}, retrying in 10 ms"); + log::warn!("Writing config failed: {e}, retrying in 10 ms"); sleep(Duration::from_millis(10)); confy::store_path(path, ctx).wrap_err("Failed to store configuration file") }), None => confy::store("pet-monitor-app", Some("config"), ctx.clone()).or_else(|e| { - tracing::warn!("Writing config failed: {e}, retrying in 10 ms"); + log::warn!("Writing config failed: {e}, retrying in 10 ms"); sleep(Duration::from_millis(10)); confy::store("pet-monitor-app", Some("config"), ctx) .wrap_err("Failed to write config file") @@ -98,12 +98,12 @@ pub async fn store(path: Option, ctx: Context) -> eyre::Result<()> { pub async fn load(path: Option) -> eyre::Result { spawn_blocking(move || match path { Some(path) => confy::load_path(&path).or_else(|e| { - tracing::warn!("Writing config failed: {e}, retrying in 10 ms"); + log::warn!("Writing config failed: {e}, retrying in 10 ms"); sleep(Duration::from_millis(10)); confy::load_path(path).wrap_err("Failed to store configuration file") }), None => confy::load("pet-monitor-app", Some("config")).or_else(|e| { - tracing::warn!("Writing config failed: {e}, retrying in 10 ms"); + log::warn!("Writing config failed: {e}, retrying in 10 ms"); sleep(Duration::from_millis(10)); confy::load("pet-monitor-app", Some("config")).wrap_err("Failed to write config file") }), diff --git a/crates/pet-monitor-app/src/handlers.rs b/crates/pet-monitor-app/src/handlers.rs index 4eeb8abc..636f322b 100644 --- a/crates/pet-monitor-app/src/handlers.rs +++ b/crates/pet-monitor-app/src/handlers.rs @@ -20,23 +20,21 @@ use mp4_stream::{ use serde::Deserialize; use tokio::task::spawn_blocking; use tower_cookies::{cookie, Cookie, Cookies}; -use tracing::instrument; macro_rules! error { ($($args:tt)*) => {{ - tracing::error!($($args)*); + log::error!($($args)*); StatusCode::INTERNAL_SERVER_ERROR }}; } #[debug_handler(state = AppState)] -#[instrument(skip_all)] pub(crate) async fn base(token: Option) -> Redirect { if token.is_some() { - tracing::debug!("Redirecting to '/stream.html'"); + log::debug!("Redirecting to '/stream.html'"); Redirect::to("/stream.html") } else { - tracing::debug!("Redirecting to '/login.html'"); + log::debug!("Redirecting to '/login.html'"); Redirect::to("/login.html") } } @@ -57,7 +55,6 @@ async fn get_file(path: &str) -> Option { } #[debug_handler] -#[instrument] pub async fn files(uri: axum::http::Uri) -> Response> { let path = uri.path().trim_start_matches('/'); #[allow(clippy::unwrap_used)] @@ -85,7 +82,6 @@ pub(crate) struct Login { } #[debug_handler] -#[instrument(skip_all)] pub(crate) async fn login( State(ctx): State, cookies: Cookies, @@ -120,7 +116,6 @@ pub(crate) async fn login( } #[debug_handler(state = AppState)] -#[instrument(skip_all)] pub(crate) async fn config( _token: Token, State(ctx): State, @@ -158,7 +153,6 @@ struct ConfigForm { } #[debug_handler(state = AppState)] -#[instrument(skip(_token, ctx, caps))] pub(crate) async fn set_config( _token: Token, State(ctx): State, @@ -191,7 +185,7 @@ pub(crate) async fn set_config( if let Err(e) = tokio::task::spawn_blocking(move || check_config(&config_clone, &caps)).await { - tracing::warn!("Config validation error: {e}"); + log::warn!("Config validation error: {e}"); return Err(StatusCode::BAD_REQUEST); } } @@ -205,7 +199,6 @@ pub(crate) async fn set_config( } #[debug_handler(state = AppState)] -#[instrument(skip_all)] pub(crate) async fn stream( _token: Token, State(ctx): State, @@ -217,7 +210,7 @@ pub(crate) async fn stream( .map_err(|e| error!("Error starting stream: {e}"))?; let stream = StreamExt::inspect(stream, |it| match it { - Err(e) => tracing::warn!("Error streaming segment: {e}"), + Err(e) => log::warn!("Error streaming segment: {e}"), Ok(_) => (), }); diff --git a/crates/pet-monitor-app/src/lib.rs b/crates/pet-monitor-app/src/lib.rs index c8a0389b..f32ab172 100644 --- a/crates/pet-monitor-app/src/lib.rs +++ b/crates/pet-monitor-app/src/lib.rs @@ -23,7 +23,6 @@ use std::{net::SocketAddr, path::PathBuf}; use tokio::task::spawn_blocking; use tower::ServiceBuilder; use tower_cookies::CookieManagerLayer; -use tower_http::trace::TraceLayer; #[derive(Debug, Clone, FromRef)] struct AppState { @@ -33,7 +32,6 @@ struct AppState { } use color_eyre::eyre; -#[tracing::instrument(skip(ctx))] pub async fn start(conf_path: Option, ctx: Context, stream: bool) -> eyre::Result<()> { let (ctx_manager, cfg_rx) = ContextManager::new(ctx.clone(), conf_path.clone()); @@ -68,7 +66,6 @@ pub async fn start(conf_path: Option, ctx: Context, stream: bool) -> ey .route("/config.html", get(handlers::config)) .route("/config.html", post(handlers::set_config)) .layer(CookieManagerLayer::new()) - .layer(TraceLayer::new_for_http()) .layer(middleware::from_fn(auth::auth_error_layer)); if stream { @@ -76,10 +73,10 @@ pub async fn start(conf_path: Option, ctx: Context, stream: bool) -> ey let config = ctx.config.clone(); spawn_blocking(move || { if let Err(e) = stream_media_segments(rx, config, Some(cfg_rx)) { - tracing::error!("Streaming error: {e}"); + log::error!("Streaming error: {e}"); } }); - tracing::info!("Stream started"); + log::info!("Stream started"); app = app.route("/stream.mp4", get(handlers::stream)); state.stream_sub_tx = Some(tx); } @@ -88,7 +85,7 @@ pub async fn start(conf_path: Option, ctx: Context, stream: bool) -> ey let addr = SocketAddr::new(ctx.host, ctx.port); - tracing::info!("Listening on {addr}"); + log::info!("Listening on {addr}"); axum::Server::bind(&addr) .serve(app.into_make_service()) .await?;