Skip to content

Commit cb19995

Browse files
authored
fix: generic server log info output even on higher log levels (#542)
It fixes an issue (previously an ad-hoc and inconsistent behavior) where SWS printed INFO-level messages at startup despite setting up a higher log level. E.g., `WARN` or `ERROR`. Notice: For consistency reasons, SWS now won't persistently show server information at startup independently of the log level as it did before. Instead, those info log entries are non-persistent and under the normal `INFO` log level. For example, to show those logs again then use the `INFO` log level. $ static-web-server -p 8787 -d public/ -g info
1 parent a384d92 commit cb19995

17 files changed

+51
-80
lines changed

src/basic_auth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{error_page, handler::RequestHandlerOpts, http_ext::MethodExt, Error}
1515
/// Initializes `Basic` HTTP Authorization handling
1616
pub(crate) fn init(credentials: &str, handler_opts: &mut RequestHandlerOpts) {
1717
credentials.trim().clone_into(&mut handler_opts.basic_auth);
18-
server_info!(
18+
tracing::info!(
1919
"basic authentication: enabled={}",
2020
!handler_opts.basic_auth.is_empty()
2121
);

src/bin/server.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ fn main() -> Result {
2525
}
2626

2727
if let Some(commands) = opts.general.commands {
28-
use static_web_server::server_info;
29-
3028
match commands {
3129
#[cfg(windows)]
3230
Commands::Install {} => {
@@ -45,13 +43,13 @@ fn main() -> Result {
4543
let mut comp_dir = out_dir.clone();
4644
comp_dir.push("completions");
4745
clap_allgen::render_shell_completions::<General>(&comp_dir)?;
48-
server_info!("wrote completions to {}", comp_dir.to_string_lossy());
46+
tracing::info!("wrote completions to {}", comp_dir.to_string_lossy());
4947
}
5048
if man_pages || !completions {
5149
let mut man_dir = out_dir.clone();
5250
man_dir.push("man");
5351
clap_allgen::render_manpages::<General>(&man_dir)?;
54-
server_info!("wrote man pages to {}", man_dir.to_string_lossy());
52+
tracing::info!("wrote man pages to {}", man_dir.to_string_lossy());
5553
}
5654
return Ok(());
5755
}

src/compression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn init(enabled: bool, level: CompressionLevel, handler_opts: &mut RequestHa
8282
#[cfg(any(feature = "compression", feature = "compression-zstd"))]
8383
"zstd",
8484
];
85-
server_info!(
85+
tracing::info!(
8686
"auto compression: enabled={enabled}, formats={}, compression level={level:?}",
8787
FORMATS.join(",")
8888
);

src/compression_static.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct CompressedFileVariant {
3131
/// Initializes static compression.
3232
pub fn init(enabled: bool, handler_opts: &mut RequestHandlerOpts) {
3333
handler_opts.compression_static = enabled;
34-
server_info!("compression static: enabled={enabled}");
34+
tracing::info!("compression static: enabled={enabled}");
3535
}
3636

3737
/// Post-processing to add Vary header if necessary.

src/control_headers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const CACHE_EXT_ONE_YEAR: [&str; 32] = [
2626

2727
pub(crate) fn init(enabled: bool, handler_opts: &mut RequestHandlerOpts) {
2828
handler_opts.cache_control_headers = enabled;
29-
server_info!("cache control headers: enabled={enabled}");
29+
tracing::info!("cache control headers: enabled={enabled}");
3030
}
3131

3232
/// Appends `Cache-Control` header to a response if necessary

src/cors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn new(
7171
};
7272

7373
if cors_res.is_some() {
74-
server_info!(
74+
tracing::info!(
7575
"cors enabled=true, allow_methods=[GET,HEAD,OPTIONS], allow_origins={}, allow_headers=[{}], expose_headers=[{}]",
7676
origins_str,
7777
allow_headers_str,

src/directory_listing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ pub struct DirListOpts<'a> {
6161
/// Initializes directory listings.
6262
pub fn init(enabled: bool, order: u8, format: DirListFmt, handler_opts: &mut RequestHandlerOpts) {
6363
handler_opts.dir_listing = enabled;
64-
server_info!("directory listing: enabled={enabled}");
64+
tracing::info!("directory listing: enabled={enabled}");
6565

6666
handler_opts.dir_listing_order = order;
67-
server_info!("directory listing order code: {order}");
67+
tracing::info!("directory listing order code: {order}");
6868

6969
handler_opts.dir_listing_format = format;
70-
server_info!(
70+
tracing::info!(
7171
"directory listing format: {:?}",
7272
handler_opts.dir_listing_format
7373
);

src/fallback_page.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) fn init(file_path: &Path, handler_opts: &mut RequestHandlerOpts) {
2626
tracing::debug!("fallback page path not found or not a regular file");
2727
}
2828

29-
server_info!(
29+
tracing::info!(
3030
"fallback page: enabled={}, value=\"{}\"",
3131
found,
3232
file_path.display()

src/health.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{handler::RequestHandlerOpts, Error};
1414
/// Initializes the health endpoint.
1515
pub fn init(enabled: bool, handler_opts: &mut RequestHandlerOpts) {
1616
handler_opts.health = enabled;
17-
server_info!("health endpoint: enabled={enabled}");
17+
tracing::info!("health endpoint: enabled={enabled}");
1818
}
1919

2020
/// Handles health requests.

src/log_addr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ pub(crate) fn init(enabled: bool, handler_opts: &mut RequestHandlerOpts) {
2020
format!("{:?}", handler_opts.trusted_proxies)
2121
};
2222

23-
server_info!("log requests with remote IP addresses: enabled={enabled}");
24-
server_info!(
23+
tracing::info!("log requests with remote IP addresses: enabled={enabled}");
24+
tracing::info!(
2525
"log X-Real-IP header: enabled={}",
2626
handler_opts.log_forwarded_for
2727
);
28-
server_info!(
28+
tracing::info!(
2929
"log X-Forwarded-For header: enabled={}",
3030
handler_opts.log_forwarded_for
3131
);
32-
server_info!("trusted IPs for X-Forwarded-For: {trusted}");
32+
tracing::info!("trusted IPs for X-Forwarded-For: {trusted}");
3333
}
3434

3535
/// It logs remote and real IP addresses if available.

0 commit comments

Comments
 (0)