From c456cba7fdec0ff0f7a3d7b0395d22029f33ccde Mon Sep 17 00:00:00 2001 From: Zhai Feiyue <80079571+ZhaiFeiyue@users.noreply.github.com> Date: Tue, 14 Apr 2026 08:28:00 +0800 Subject: [PATCH] [gateway] Support SGLANG_LOG_MS for millisecond precision in router logs (#22506) --- sgl-model-gateway/src/observability/logging.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sgl-model-gateway/src/observability/logging.rs b/sgl-model-gateway/src/observability/logging.rs index 188d9b1b1..a85fbdd7f 100644 --- a/sgl-model-gateway/src/observability/logging.rs +++ b/sgl-model-gateway/src/observability/logging.rs @@ -16,8 +16,16 @@ use super::otel_trace::get_otel_layer; use crate::config::TraceConfig; const TIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S"; +const TIME_FORMAT_MS: &str = "%Y-%m-%d %H:%M:%S%.3f"; const DEFAULT_LOG_TARGET: &str = "smg"; +fn get_time_format() -> &'static str { + match std::env::var("SGLANG_LOG_MS") { + Ok(v) if matches!(v.trim().to_lowercase().as_str(), "true" | "1") => TIME_FORMAT_MS, + _ => TIME_FORMAT, + } +} + #[derive(Debug, Clone)] pub struct LoggingConfig { pub level: Level, @@ -102,11 +110,13 @@ pub fn init_logging(config: LoggingConfig, otel_layer_config: Option