From bb2a379c59104ef7767e408c27cf869f788105fa Mon Sep 17 00:00:00 2001 From: Jeena Date: Fri, 16 Jan 2026 11:55:37 +0000 Subject: [PATCH] Fix log format spacing: single space between timestamp and level - Replace tracing compact format with custom FormatEvent - Eliminate double space padding between timestamp and log level - Clean single-space formatting: timestamp level message - Maintain all existing log content and functionality --- src/logging.rs | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/logging.rs b/src/logging.rs index 2ac0ed5..5ec49ad 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -1,15 +1,35 @@ use tokio::net::TcpStream; use tokio_rustls::server::TlsStream; -use tracing_subscriber::fmt::time::FormatTime; +use tracing_subscriber::fmt::format::Writer; +use tracing_subscriber::fmt::FormatFields; -struct GeminiTimeFormat; +struct CleanLogFormatter; -impl FormatTime for GeminiTimeFormat { - fn format_time(&self, w: &mut tracing_subscriber::fmt::format::Writer<'_>) -> std::fmt::Result { +impl tracing_subscriber::fmt::FormatEvent for CleanLogFormatter +where + S: tracing::Subscriber + for<'a> tracing_subscriber::registry::LookupSpan<'a>, + N: for<'a> tracing_subscriber::fmt::FormatFields<'a> + 'static, +{ + fn format_event( + &self, + ctx: &tracing_subscriber::fmt::FmtContext<'_, S, N>, + mut writer: Writer<'_>, + event: &tracing::Event<'_>, + ) -> std::fmt::Result { + // Write timestamp let now = time::OffsetDateTime::now_utc(); - write!(w, "{}-{:02}-{:02}T{:02}:{:02}:{:02}", + write!(writer, "{}-{:02}-{:02}T{:02}:{:02}:{:02} ", now.year(), now.month() as u8, now.day(), - now.hour(), now.minute(), now.second()) + now.hour(), now.minute(), now.second())?; + + // Write level + let level = event.metadata().level(); + write!(writer, "{} ", level)?; + + // Write the message + ctx.format_fields(writer.by_ref(), event)?; + + writeln!(writer) } } @@ -74,10 +94,7 @@ pub fn init_logging(level: &str) { tracing_subscriber::registry() .with(tracing_subscriber::fmt::layer() - .compact() - .with_timer(GeminiTimeFormat) - .with_target(false) - .with_thread_ids(false)) + .event_format(CleanLogFormatter)) .with(tracing_subscriber::filter::LevelFilter::from_level(level)) .init(); }