Add a custom log function

This commit is contained in:
Juno Takano 2025-12-13 16:28:13 -03:00
commit 4db4c703d1
5 changed files with 32 additions and 14 deletions

View file

@ -6,6 +6,7 @@ use axum::{
use crate::formats::{Format, populate_graph, serialize_graph};
use crate::handlers;
#[expect(clippy::unused_async)]
pub async fn file(file_path: &str, content_type: &str) -> Response<Body> {
let content = match std::fs::read(file_path) {
Ok(s) => s,
@ -20,21 +21,24 @@ pub async fn file(file_path: &str, content_type: &str) -> Response<Body> {
if let Ok(header_value) = HeaderValue::from_str(content_type) {
if let Some(h) = response.headers_mut().insert(header, header_value) {
eprintln!(
"[file_handler] Overwrote existing header {h:?} \
because a header for the same key existed"
crate::dev::log(
&file,
&format!("Overwrote existing header {h:?} because a header for \
the same key existed")
);
}
} else {
eprintln!(
"[file_handler] Failed to create content type \
header value from {content_type}"
crate::dev::log(
&file,
&format!("[file_handler] Failed to create content type \
header value from {content_type}")
);
}
response
}
#[expect(clippy::unused_async)]
pub async fn serial(format: &Format) -> Response<Body> {
let graph = populate_graph();
let body = serialize_graph(format, &graph);

View file

@ -7,6 +7,7 @@ use axum::{
use crate::{formats::populate_graph, types::Node, handlers};
#[expect(clippy::unused_async)]
pub async fn nexus(template: &str) -> Response<Body> {
let mut context = tera::Context::new();
let graph = populate_graph();

View file

@ -18,16 +18,17 @@ pub fn make_response(
if let Some(overwritten) =
response.headers_mut().insert(header.0.clone(), wrapped)
{
eprintln!(
"[make_response] Overwrote header {overwritten:?} \
crate::dev::log(
&make_response,
&format!("Overwrote header {overwritten:?} \
because another for key {} already existed",
header.0
header.0)
);
}
} else {
eprintln!(
"[make_response] Failed to wrap header value {}",
header.1
crate::dev::log(
&make_response,
&format!("Failed to wrap header value {}", header.1)
);
}
}