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
This commit is contained in:
Jeena 2026-01-16 11:55:37 +00:00
parent 6c6d4bc613
commit bb2a379c59

View file

@ -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<S, N> tracing_subscriber::fmt::FormatEvent<S, N> 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();
}