Fix logging format: use request path instead of file path, clean timestamp
- Log request paths (/big-file.mkv) instead of file system paths - Custom timestamp format: YYYY-MM-DDTHH:MM:SSZ (no milliseconds) - Update serve_file to accept request parameter for proper logging - Strip gemini://host prefix from logged requests for cleaner logs - Add time crate for custom timestamp formatting
This commit is contained in:
parent
3865211554
commit
051157a84c
3 changed files with 22 additions and 4 deletions
|
|
@ -14,6 +14,7 @@ static ACTIVE_REQUESTS: AtomicUsize = AtomicUsize::new(0);
|
|||
pub async fn serve_file(
|
||||
stream: &mut TlsStream<TcpStream>,
|
||||
file_path: &Path,
|
||||
request: &str,
|
||||
) -> io::Result<()> {
|
||||
if file_path.exists() && file_path.is_file() {
|
||||
let mime_type = get_mime_type(file_path);
|
||||
|
|
@ -24,7 +25,8 @@ pub async fn serve_file(
|
|||
Ok(addr) => addr.to_string(),
|
||||
Err(_) => "unknown".to_string(),
|
||||
};
|
||||
tracing::info!("{} \"file:{}\" 20 \"Success\"", client_ip, file_path.display());
|
||||
let request_path = request.strip_prefix("gemini://localhost").unwrap_or(request);
|
||||
tracing::info!("{} \"{}\" 20 \"Success\"", client_ip, request_path);
|
||||
// Then send body
|
||||
let content = fs::read(file_path)?;
|
||||
stream.write_all(&content).await?;
|
||||
|
|
@ -124,7 +126,7 @@ pub async fn handle_connection(
|
|||
// Processing complete
|
||||
|
||||
// Serve the file
|
||||
match serve_file(&mut stream, &file_path).await {
|
||||
match serve_file(&mut stream, &file_path, &request).await {
|
||||
Ok(_) => {
|
||||
// Success already logged in serve_file
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue