From a124122dd4e2d9e58da2b2a26e3fb2222e8d5c6a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 24 Apr 2024 02:34:21 -0700 Subject: [PATCH] daily logging improvements Signed-off-by: Jason Volk --- src/api/client_server/media.rs | 21 ++++++++------------- src/service/rooms/event_handler/mod.rs | 4 ++-- src/utils/error.rs | 3 +-- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/api/client_server/media.rs b/src/api/client_server/media.rs index e30ac373..bed79bc1 100644 --- a/src/api/client_server/media.rs +++ b/src/api/client_server/media.rs @@ -10,10 +10,11 @@ use ruma::api::client::{ get_media_preview, }, }; -use tracing::{debug, error, info, warn}; +use tracing::{debug, error, warn}; use webpage::HTML; use crate::{ + debug_warn, service::media::{FileMeta, UrlPreviewData}, services, utils, Error, Result, Ruma, RumaResponse, }; @@ -324,17 +325,14 @@ pub(crate) async fn get_content_thumbnail_route( cache_control: Some(CACHE_CONTROL_IMMUTABLE.into()), }) } else if &*body.server_name != services().globals.server_name() && body.allow_remote { - // we'll lie to the client and say the blocked server's media was not found and - // log. the client has no way of telling anyways so this is a security bonus. if services() .globals .prevent_media_downloads_from() .contains(&body.server_name.clone()) { - info!( - "Received request for remote media `{}` but server is in our media server blocklist. Returning 404.", - mxc - ); + // we'll lie to the client and say the blocked server's media was not found and + // log. the client has no way of telling anyways so this is a security bonus. + debug_warn!("Received request for media `{}` on blocklisted server", mxc); return Err(Error::BadRequest(ErrorKind::NotFound, "Media not found.")); } @@ -402,17 +400,14 @@ pub(crate) async fn get_content_thumbnail_v1_route( async fn get_remote_content( mxc: &str, server_name: &ruma::ServerName, media_id: String, allow_redirect: bool, timeout_ms: Duration, ) -> Result { - // we'll lie to the client and say the blocked server's media was not found and - // log. the client has no way of telling anyways so this is a security bonus. if services() .globals .prevent_media_downloads_from() .contains(&server_name.to_owned()) { - info!( - "Received request for remote media `{}` but server is in our media server blocklist. Returning 404.", - mxc - ); + // we'll lie to the client and say the blocked server's media was not found and + // log. the client has no way of telling anyways so this is a security bonus. + debug_warn!("Received request for media `{}` on blocklisted server", mxc); return Err(Error::BadRequest(ErrorKind::NotFound, "Media not found.")); } diff --git a/src/service/rooms/event_handler/mod.rs b/src/service/rooms/event_handler/mod.rs index 629ad626..60ac41be 100644 --- a/src/service/rooms/event_handler/mod.rs +++ b/src/service/rooms/event_handler/mod.rs @@ -25,7 +25,7 @@ use tracing::{debug, error, info, trace, warn}; use super::state_compressor::CompressedStateEvent; use crate::{ - debug_info, + debug_error, debug_info, service::{pdu, Arc, BTreeMap, HashMap, Result}, services, Error, PduEvent, }; @@ -1103,7 +1103,7 @@ impl Service { events_all.insert(next_id); }, Err(e) => { - warn!("Failed to fetch event {next_id}: {e}"); + debug_error!("Failed to fetch event {next_id}: {e}"); back_off((*next_id).to_owned()).await; }, } diff --git a/src/utils/error.rs b/src/utils/error.rs index d25d43d1..04ed6bf3 100644 --- a/src/utils/error.rs +++ b/src/utils/error.rs @@ -15,7 +15,7 @@ use ErrorKind::{ TooLarge, Unauthorized, Unknown, UnknownToken, Unrecognized, UserDeactivated, WrongRoomKeysVersion, }; -use crate::{debug_info, RumaResponse}; +use crate::RumaResponse; pub(crate) type Result = std::result::Result; @@ -139,7 +139,6 @@ impl Error { _ => (Unknown, StatusCode::INTERNAL_SERVER_ERROR), }; - debug_info!("Returning an error: {status_code}: {message}"); RumaResponse(UiaaResponse::MatrixError(RumaError { body: ErrorBody::Standard { kind,