Implement log levels
This commit is contained in:
parent
2cdf68082a
commit
874cac2df1
25 changed files with 497 additions and 223 deletions
|
|
@ -13,6 +13,7 @@ use crate::{
|
|||
/// Will panic if file read fails.
|
||||
#[expect(clippy::unused_async)]
|
||||
pub async fn file(file_path: &str, content_type: &str) -> Response<Body> {
|
||||
let instant = now();
|
||||
let content = match std::fs::read(file_path) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
|
|
@ -27,9 +28,16 @@ pub async fn file(file_path: &str, content_type: &str) -> Response<Body> {
|
|||
if let Ok(header_value) = HeaderValue::from_str(content_type) {
|
||||
response.headers_mut().append(header, header_value);
|
||||
} else {
|
||||
log!("Failed to create content type header value from {content_type}");
|
||||
log!(
|
||||
WARN,
|
||||
"Failed to create content type header value from {content_type}"
|
||||
);
|
||||
}
|
||||
|
||||
tlog!(
|
||||
&instant,
|
||||
"Assembled response for {content_type} {file_path}"
|
||||
);
|
||||
response
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use axum::response::IntoResponse as _;
|
||||
use axum::{body::Body, extract::Path, http::Response, response::Redirect};
|
||||
|
||||
use crate::{graph::Graph, router::handlers, graph::Node};
|
||||
use crate::{prelude::*, graph::Graph, router::handlers, graph::Node};
|
||||
|
||||
pub async fn node(Path(id): Path<String>) -> Response<Body> {
|
||||
let instant = now();
|
||||
let graph = Graph::load();
|
||||
let result = graph.find_node(&id);
|
||||
let found = result.node.is_some();
|
||||
|
|
@ -28,6 +29,7 @@ pub async fn node(Path(id): Path<String>) -> Response<Body> {
|
|||
context.insert("node", &node);
|
||||
context.insert("incoming", &graph.incoming.get(&id));
|
||||
|
||||
tlog!(&instant, "Assembled response for node {}", node.id);
|
||||
handlers::template::by_filename(
|
||||
"node.html",
|
||||
&context,
|
||||
|
|
|
|||
|
|
@ -6,21 +6,25 @@ use axum::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
prelude::*,
|
||||
graph::{Graph, Node},
|
||||
router::handlers,
|
||||
};
|
||||
|
||||
#[expect(clippy::unused_async)]
|
||||
pub async fn page(template: &str) -> Response<Body> {
|
||||
let instant = now();
|
||||
let mut context = tera::Context::default();
|
||||
let graph = Graph::load();
|
||||
|
||||
context.insert("graph", &graph);
|
||||
|
||||
tlog!(&instant, "Assembled response for template {template}");
|
||||
handlers::template::by_filename(template, &context, 500, None, false)
|
||||
}
|
||||
|
||||
pub async fn tree() -> Response<Body> {
|
||||
let instant = now();
|
||||
let mut context = tera::Context::default();
|
||||
let mut graph = Graph::load();
|
||||
|
||||
|
|
@ -39,10 +43,12 @@ pub async fn tree() -> Response<Body> {
|
|||
);
|
||||
}
|
||||
|
||||
tlog!(&instant, "Assembled response for tree endpoint");
|
||||
handlers::template::by_filename("tree.html", &context, 500, None, false)
|
||||
}
|
||||
|
||||
pub async fn data() -> Response<Body> {
|
||||
let instant = now();
|
||||
let mut context = tera::Context::default();
|
||||
let graph = Graph::load();
|
||||
|
||||
|
|
@ -54,6 +60,7 @@ pub async fn data() -> Response<Body> {
|
|||
context.insert("detached_count", &graph.stats.detached.len());
|
||||
context.insert("detached_pairs", &detached_pairs);
|
||||
|
||||
tlog!(&instant, "Assembled response for data endpoint");
|
||||
handlers::template::by_filename("data.html", &context, 500, None, false)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,13 +21,14 @@ pub(in crate::router::handlers) fn make_response(
|
|||
response.headers_mut().insert(header.0.clone(), wrapped)
|
||||
{
|
||||
log!(
|
||||
WARN,
|
||||
"Overwrote header {overwritten:?} \
|
||||
because another for key {} already existed",
|
||||
header.0
|
||||
);
|
||||
}
|
||||
} else {
|
||||
log!("Failed to create header value from {}", header.1);
|
||||
log!(ERROR, "Failed to create header value from {}", header.1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ pub(in crate::router::handlers) fn render(
|
|||
context: &tera::Context,
|
||||
error_message: Option<String>,
|
||||
) -> (String, u16) {
|
||||
let instant = now();
|
||||
// TODO just return an Option/String> here
|
||||
let tera = match tera::Tera::new("./templates/**/*") {
|
||||
Ok(t) => t,
|
||||
|
|
@ -35,7 +36,10 @@ pub(in crate::router::handlers) fn render(
|
|||
};
|
||||
|
||||
match tera.render(name, context) {
|
||||
Ok(t) => (t, 200),
|
||||
Ok(t) => {
|
||||
tlog!(&instant, "Rendered template {name}");
|
||||
(t, 200)
|
||||
},
|
||||
Err(e) => {
|
||||
let mut error_context = tera::Context::default();
|
||||
|
||||
|
|
@ -69,7 +73,7 @@ pub(in crate::router::handlers) fn render(
|
|||
}
|
||||
|
||||
fn emergency_wrap(error: &tera::Error) -> String {
|
||||
log!("{error:#?}");
|
||||
log!(ERROR, "{error:#?}");
|
||||
format!(
|
||||
r#"<!DOCTYPE html>
|
||||
<html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue