about summary refs log tree commit diff
path: root/splorm/src/handler
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2026-09-21 16:57:59 -0500
committergennyble <gen@nyble.dev>2026-09-21 16:57:59 -0500
commit021077e7aaa35a824738a88cd00c8a379689ac45 (patch)
tree4c81eb2039a57c183f55b844fb0b1697ac3c8d7b /splorm/src/handler
parent87cceff5e578c1a84529a53cfb947171049474c5 (diff)
improve logging
Diffstat (limited to 'splorm/src/handler')
-rw-r--r--splorm/src/handler/mod.rs28
-rw-r--r--splorm/src/handler/staticfile.rs2
2 files changed, 27 insertions, 3 deletions
diff --git a/splorm/src/handler/mod.rs b/splorm/src/handler/mod.rs
index 0089c48..2db1f27 100644
--- a/splorm/src/handler/mod.rs
+++ b/splorm/src/handler/mod.rs
@@ -1,22 +1,44 @@
-use axum::{Extension, extract::Path, response::Response};
+use std::sync::Arc;
+
+use axum::{
+	Extension,
+	extract::{Path, Request},
+	middleware::Next,
+	response::Response,
+};
 
 mod staticfile;
 mod templated;
 
 use crate::{RuntimeError, config::Settings, fs::RequestPath};
 
+/// Log runtime errors using a middleware layer. Very much based on the [axum
+/// error_handling example][axum_errorhandling]
+/// [axum_errorhandling]: https://github.com/tokio-rs/axum/blob/3696bfe5f1c30ee57f39dfb992b01bbf57bf2c1f/examples/error-handling/src/main.rs
+pub async fn log_errors(request: Request, next: Next) -> Response {
+	let response = next.run(request).await;
+	if let Some(runtime_error) = response.extensions().get::<Arc<RuntimeError>>() {
+		tracing::error!("{runtime_error}")
+	}
+	response
+}
+
+/// GET /
 pub async fn index(Extension(settings): Extension<Settings>) -> Result<Response, RuntimeError> {
-	println!("index!");
+	tracing::info!("GET /");
 	let rqp = RequestPath::verify_safe(settings.root(), "home.html")?;
 	templated::send_file(rqp, &settings).await
 }
 
+/// GET /{*path}
 pub async fn static_path(
 	Extension(settings): Extension<Settings>,
 	Path(path): Path<String>,
 ) -> Result<Response, RuntimeError> {
-	println!("{path}");
+	tracing::trace!("static_path with {path}");
 	let rqp = RequestPath::verify_safe(settings.root(), &path)?;
+	tracing::info!("GET /{}", rqp.web_path());
+
 	if rqp.guess_mime().as_ref() == "text/html" {
 		templated::send_file(rqp, &settings).await
 	} else {
diff --git a/splorm/src/handler/staticfile.rs b/splorm/src/handler/staticfile.rs
index 8f26251..cb818ba 100644
--- a/splorm/src/handler/staticfile.rs
+++ b/splorm/src/handler/staticfile.rs
@@ -11,8 +11,10 @@ pub async fn send_or_stream_file(path: RequestPath) -> Result<Response, RuntimeE
 	let meta = path.system_path().metadata()?;
 
 	if meta.len() > STREAM_AFTER {
+		tracing::trace!("File is large, Streaming");
 		stream_file(path).await
 	} else {
+		tracing::trace!("File is small, Sending");
 		send_file(path).await
 	}
 }