Skip to content
Snippets Groups Projects
Verified Commit 12f99692 authored by Volkor Barbarian Warrior's avatar Volkor Barbarian Warrior
Browse files

fix: improve logging

parent 3438a655
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ use salvo::{
Request, Response,
};
use std::time::SystemTime;
use tracing::debug;
use tracing::{debug, info, error};
use crate::{
db::{self, FileCheckResult},
......@@ -28,7 +28,7 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
.param("file")
.expect("Failed to set the filename variable");
tracing::info!("New File View: {:?}", &filename.to_string());
info!("[{}]File View: {:?}", &headers[HOST].to_str().unwrap(), &filename.to_string());
// Get a new sql pool thingy
let sqlconn = SQLITE.get().expect("Failed to grab sqlite pool");
......@@ -47,7 +47,7 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
.any(|mime| mime.clone() == mimetype.clone())
{
// Check if any of the unsafe mime types match the given mimetype
tracing::info!("Unsafe Extension Filtered: {:?}", mimetype);
info!("Unsafe Extension Filtered: {:?}", mimetype);
mimetype = String::from("text/plain"); // If there is a match, change the mimetype to text/plain
}
......@@ -62,12 +62,12 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
db::update_fileview(sqlconn, &filename, accessed)
.await
.unwrap_or_else(|err| {
tracing::error!(
error!(
"Failed to update fileview for file: {} error: {:?}",
&filename,
err
);
tracing::error!("soft-setting fileview to 0 for file: {}", &filename);
error!("soft-setting fileview to 0 for file: {}", &filename);
0
});
......@@ -89,7 +89,7 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
res.add_header("Content-Type", mimetype, true).unwrap();
// Go through all the headers and print them out, just to check for now!
tracing::debug!("response headers: {:?}", res.headers());
debug!("response headers: {:?}", res.headers());
// https://github.com/salvo-rs/salvo/issues/233
res.status_code(StatusCode::OK);
......@@ -106,7 +106,7 @@ pub async fn render_file(req: &mut Request, res: &mut Response, headers: HeaderM
res.add_header("Content-Type", mimetype, true).unwrap();
// Go through all the headers and print them out, just to check for now!
tracing::debug!("response headers: {:?}", res.headers());
debug!("response headers: {:?}", res.headers());
res.status_code(StatusCode::OK);
}
......@@ -169,16 +169,16 @@ pub async fn serve_file(req: &mut Request, res: &mut Response) {
match check_file_exists(&filename, "files/").await {
// File does exist in the filesystem!
true => {
debug!("Adding previously unknown file to the database.");
info!("Adding previously unknown file to the database: {}", &filename);
// Add the file to the database
match add_undeleted_file(&filename).await {
Ok(_) => {
tracing::info!("Successfully added file back into the database");
info!("Successfully added {} back into the database", &filename);
// Now we can render the file!
render_file(req, res, headers).await
}
Err(_) => {
tracing::error!("Error while adding file back into the database");
error!("Error while adding {} back into the database", &filename);
// TODO: Refactor a nice error rendering function, were we just pass the errorcode, and message
render_404(res, upload_by_web, headers).await
}
......@@ -186,7 +186,7 @@ pub async fn serve_file(req: &mut Request, res: &mut Response) {
}
// File doesn't exist in the filesystem :(
false => {
tracing::debug!("Double checked, file truly doesn't exist.");
debug!("Double checked, {} truly doesn't exist.", &filename);
render_404(res, upload_by_web, headers).await
}
}
......@@ -194,7 +194,7 @@ pub async fn serve_file(req: &mut Request, res: &mut Response) {
// Error while finding file in the database
Err(err) => {
tracing::error!("Error while trying to check the filename: {:?}", err);
error!("Error while trying to check the filename: {:?}", err);
if upload_by_web {
let template_filename = "error.html";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment