Skip to content

Commit

Permalink
feat: log server requests in verbose mode #113
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKreil committed Sep 30, 2024
1 parent c74bae3 commit 27f517e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
3 changes: 1 addition & 2 deletions versatiles/src/tools/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{
types::{TileBBoxPyramid, TileCompression},
};
use anyhow::{bail, Result};
use log::trace;

#[derive(clap::Args, Debug)]
#[command(arg_required_else_help = true, disable_version_flag = true)]
Expand Down Expand Up @@ -99,7 +98,7 @@ fn get_bbox_pyramid(arguments: &Subcommand) -> Result<Option<TileBBoxPyramid>> {
}

if let Some(bbox) = &arguments.bbox {
trace!("parsing bbox argument: {:?}", bbox);
log::trace!("parsing bbox argument: {:?}", bbox);
let values: Vec<f64> = bbox
.split(&[' ', ',', ';'])
.filter(|s| !s.is_empty())
Expand Down
3 changes: 1 addition & 2 deletions versatiles/src/tools/server/sources/static_source_tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
};
use anyhow::{bail, ensure, Result};
use async_trait::async_trait;
use log::trace;
use std::{
collections::HashMap, env::current_dir, ffi::OsStr, fmt::Debug, fs::File, io::Read, path::Path,
};
Expand Down Expand Up @@ -107,7 +106,7 @@ impl TarFile {
name = name[1..].to_string();
}

trace!("Adding file from tar: {} ({:?})", name, compression);
log::trace!("Adding file from tar: {} ({:?})", name, compression);

let entry = lookup.entry(name);
let versions = entry.or_insert_with(|| FileEntry::new(mime.to_string()));
Expand Down
6 changes: 5 additions & 1 deletion versatiles/src/tools/server/sources/tile_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ impl TileSource {
// Create a TileCoord3 instance
let coord = TileCoord3::new(x.unwrap(), y.unwrap(), z.unwrap()).unwrap();

log::debug!("get tile {} - {:?}", self.prefix, coord);
log::debug!(
"get tile, prefix: {}, coord: {}",
self.prefix,
coord.as_json()
);

// Get tile data
let reader = self.reader.lock().await;
Expand Down
17 changes: 15 additions & 2 deletions versatiles/src/tools/server/tile_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ impl TileServer {
) -> Response<Body> {
let path = Url::new(uri.path());

log::debug!("handle tile request: {path}");

let mut target_compressions = get_encoding(headers);
target_compressions.set_best_compression(best_compression);

Expand All @@ -161,10 +163,10 @@ impl TileServer {
.await;

if let Some(response) = response {
log::warn!("{}: {path} found", tile_source.prefix);
log::info!("send response to tile request: {path}");
ok_data(response, target_compressions)
} else {
log::warn!("{}: {path} not found", tile_source.prefix);
log::warn!("send 404 to tile request: {path}");
ok_not_found()
}
}
Expand All @@ -187,6 +189,8 @@ impl TileServer {
) -> Response<Body> {
let mut url = Url::new(uri.path());

log::debug!("handle static request: {url}");

if url.is_dir() {
url.push("index.html");
}
Expand All @@ -196,10 +200,12 @@ impl TileServer {

for source in sources.iter() {
if let Some(result) = source.get_data(&url, &compressions) {
log::info!("send response to static request: {url}");
return ok_data(result, compressions);
}
}

log::warn!("send 404 to static request: {url}");
ok_not_found()
}
}
Expand Down Expand Up @@ -272,6 +278,11 @@ fn ok_data(result: SourceResponse, target_compressions: TargetCompression) -> Re
let (blob, compression) = if is_incompressible {
(result.blob, result.compression)
} else {
log::trace!(
"optimize_compression from \"{}\" to {:?}",
result.compression,
target_compressions
);
optimize_compression(result.blob, &result.compression, target_compressions)
.expect("should have optimized compression")
};
Expand All @@ -283,6 +294,8 @@ fn ok_data(result: SourceResponse, target_compressions: TargetCompression) -> Re
Brotli => response = response.header(CONTENT_ENCODING, "br"),
}

log::trace!("send repsonse using headers: {:?}", response.headers_ref());

response
.body(Body::from(blob.into_vec()))
.expect("should have build a body")
Expand Down

0 comments on commit 27f517e

Please sign in to comment.