From e03883fe76540c92a33e144ae593a417b06dcefc Mon Sep 17 00:00:00 2001 From: Liran Amrani Date: Tue, 9 Sep 2025 13:32:27 +0300 Subject: [PATCH] Fix missing timestamps in file logging output Problem: When using file logging (log_file configuration), log messages written to files lack timestamps, while console output includes them. This inconsistency makes it difficult to correlate events and analyze logs when file logging is used. The issue occurs because the MultiWriter sends logs to both console (with timestamp wrapper) and file (without timestamp wrapper) outputs. Solution: Wrap the file writer with the same logWriter that adds timestamps to console output. This ensures both console and file logs have identical timestamp formatting while preserving all existing functionality including log rotation. Changes: - Modified logging/logging.go to wrap logFile with logWriter before adding to MultiWriter - Preserves log rotation, filtering, and all other existing features - No configuration changes required - Maintains same performance characteristics Fixes timestamp inconsistency between console and file logging output. --- logging/logging.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/logging/logging.go b/logging/logging.go index e1275283d..74ba1daab 100644 --- a/logging/logging.go +++ b/logging/logging.go @@ -119,7 +119,9 @@ func newWriter(config *Config) (io.Writer, error) { if err := logFile.openNew(); err != nil { return nil, fmt.Errorf("error setting up log_file logging : %w", err) } - logOutput = io.MultiWriter(logOutput, logFile) + // Wrap the log file with timestamp formatting to match console output + logFileWithTimestamp := logWriter{out: logFile} + logOutput = io.MultiWriter(logOutput, logFileWithTimestamp) } if config.Syslog {