From ed77060679a81104cdc5583638e79efb4e08f4bd Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Sat, 11 May 2024 03:36:36 -0700 Subject: [PATCH] wip: convert more log messages to traces --- core/lib/src/fs/server.rs | 20 ++++++++++---------- core/lib/src/fs/temp_file.rs | 13 ++++++------- core/lib/src/response/flash.rs | 3 --- core/lib/src/router/matcher.rs | 13 ++++++------- core/lib/src/server.rs | 1 - core/lib/src/state.rs | 8 ++++---- 6 files changed, 26 insertions(+), 32 deletions(-) diff --git a/core/lib/src/fs/server.rs b/core/lib/src/fs/server.rs index 45300db592..faa95f11d0 100644 --- a/core/lib/src/fs/server.rs +++ b/core/lib/src/fs/server.rs @@ -142,20 +142,20 @@ impl FileServer { /// ``` #[track_caller] pub fn new>(path: P, options: Options) -> Self { - use crate::yansi::Paint; - let path = path.as_ref(); if !options.contains(Options::Missing) { if !options.contains(Options::IndexFile) && !path.is_dir() { - let path = path.display(); - error!("FileServer path '{}' is not a directory.", path.primary()); - warn_!("Aborting early to prevent inevitable handler error."); - panic!("invalid directory: refusing to continue"); + error!(path = %path.display(), + "FileServer path does not point to a directory.\n\ + Aborting early to prevent inevitable handler runtime errors."); + + panic!("invalid directory path: refusing to continue"); } else if !path.exists() { - let path = path.display(); - error!("FileServer path '{}' is not a file.", path.primary()); - warn_!("Aborting early to prevent inevitable handler error."); - panic!("invalid file: refusing to continue"); + error!(path = %path.display(), + "FileServer path does not point to a file.\n\ + Aborting early to prevent inevitable handler runtime errors."); + + panic!("invalid file path: refusing to continue"); } } diff --git a/core/lib/src/fs/temp_file.rs b/core/lib/src/fs/temp_file.rs index 5a61298bf5..0464dd46ce 100644 --- a/core/lib/src/fs/temp_file.rs +++ b/core/lib/src/fs/temp_file.rs @@ -554,17 +554,16 @@ impl<'r> FromData<'r> for Capped> { type Error = io::Error; async fn from_data(req: &'r Request<'_>, data: Data<'r>) -> data::Outcome<'r, Self> { - use yansi::Paint; - let has_form = |ty: &ContentType| ty.is_form_data() || ty.is_form(); if req.content_type().map_or(false, has_form) { - let (tf, form) = ("TempFile<'_>".primary(), "Form>".primary()); - warn_!("Request contains a form that will not be processed."); - info_!("Bare `{}` data guard writes raw, unprocessed streams to disk.", tf); - info_!("Did you mean to use `{}` instead?", form); + warn!(request.content_type = req.content_type().map(display), + "Request contains a form that is not being processed.\n\ + Bare `TempFile` data guard writes raw, unprocessed streams to disk\n\ + Perhaps you meant to use `Form>` instead?"); } - TempFile::from(req, data, None, req.content_type().cloned()).await + TempFile::from(req, data, None, req.content_type().cloned()) + .await .or_error(Status::BadRequest) } } diff --git a/core/lib/src/response/flash.rs b/core/lib/src/response/flash.rs index 688e6d0e2b..279ec854b6 100644 --- a/core/lib/src/response/flash.rs +++ b/core/lib/src/response/flash.rs @@ -244,10 +244,7 @@ impl<'r> FromRequest<'r> for FlashMessage<'r> { type Error = (); async fn from_request(req: &'r Request<'_>) -> request::Outcome { - trace_!("Flash: attempting to retrieve message."); req.cookies().get(FLASH_COOKIE_NAME).ok_or(()).and_then(|cookie| { - trace_!("Flash: retrieving message: {:?}", cookie); - // Parse the flash message. let content = cookie.value(); let (len_str, kv) = match content.find(FLASH_COOKIE_DELIM) { diff --git a/core/lib/src/router/matcher.rs b/core/lib/src/router/matcher.rs index 1555eae617..e0dd66d302 100644 --- a/core/lib/src/router/matcher.rs +++ b/core/lib/src/router/matcher.rs @@ -173,6 +173,7 @@ fn paths_match(route: &Route, req: &Request<'_>) -> bool { fn queries_match(route: &Route, req: &Request<'_>) -> bool { trace!( route.query = route.uri.query().map(display), + route.query.color = route.uri.metadata.query_color.map(debug), request.query = req.uri().query().map(display), ); @@ -180,17 +181,15 @@ fn queries_match(route: &Route, req: &Request<'_>) -> bool { return true; } - let route_query_fields = route.uri.metadata.static_query_fields.iter() - .map(|(k, v)| (k.as_str(), v.as_str())); - - for route_seg in route_query_fields { + let route_query_fields = route.uri.metadata.static_query_fields.iter(); + for (key, val) in route_query_fields { if let Some(query) = req.uri().query() { - if !query.segments().any(|req_seg| req_seg == route_seg) { - trace_!("request {} missing static query {:?}", req, route_seg); + if !query.segments().any(|req_seg| req_seg == (key, val)) { + debug!(key, val, request.query = %query, "missing static query"); return false; } } else { - trace_!("query-less request {} missing static query {:?}", req, route_seg); + debug!(key, val, "missing static query (queryless request)"); return false; } } diff --git a/core/lib/src/server.rs b/core/lib/src/server.rs index 6c74f9cb09..9711963f73 100644 --- a/core/lib/src/server.rs +++ b/core/lib/src/server.rs @@ -23,7 +23,6 @@ type Result = std::result::Result; impl Rocket { #[tracing::instrument("request", skip_all, fields( - timestamp = time::OffsetDateTime::now_utc().unix_timestamp_nanos(), method = %parts.method, uri = %parts.uri, autohandled diff --git a/core/lib/src/state.rs b/core/lib/src/state.rs index 9ecf24e173..58c9c62673 100644 --- a/core/lib/src/state.rs +++ b/core/lib/src/state.rs @@ -3,7 +3,6 @@ use std::ops::Deref; use std::any::type_name; use ref_cast::RefCast; -use yansi::Paint; use crate::{Phase, Rocket, Ignite, Sentinel}; use crate::request::{self, FromRequest, Request}; @@ -211,9 +210,10 @@ impl<'r, T: Send + Sync + 'static> FromRequest<'r> for &'r State { impl Sentinel for &State { fn abort(rocket: &Rocket) -> bool { if rocket.state::().is_none() { - let type_name = type_name::(); - error!("launching with unmanaged `{}` state.", type_name.primary().bold()); - info_!("Using `State` requires managing it with `.manage()`."); + error!(type_name = type_name::(), + "unmanaged state detected\n\ + ensure type is being managed via `rocket.manage()`"); + return true; }