package main import ( "fmt" "os" "time" ) // ContainerLogger provides structured logging for containers // All output goes to stdout/stderr for container runtime collection type ContainerLogger struct { name string } // NewContainerLogger creates a new container-friendly logger func NewContainerLogger(name string) *ContainerLogger { return &ContainerLogger{name: name} } // Info logs informational messages to stdout func (l *ContainerLogger) Info(msg string, args ...interface{}) { timestamp := time.Now().UTC().Format("2006-01-02T15:04:05.000Z") logMsg := fmt.Sprintf(msg, args...) fmt.Fprintf(os.Stdout, "[%s] [INFO] [%s] %s\n", timestamp, l.name, logMsg) } // Warn logs warning messages to stdout func (l *ContainerLogger) Warn(msg string, args ...interface{}) { timestamp := time.Now().UTC().Format("2006-01-02T15:04:05.000Z") logMsg := fmt.Sprintf(msg, args...) fmt.Fprintf(os.Stdout, "[%s] [WARN] [%s] %s\n", timestamp, l.name, logMsg) } // Error logs error messages to stderr func (l *ContainerLogger) Error(msg string, args ...interface{}) { timestamp := time.Now().UTC().Format("2006-01-02T15:04:05.000Z") logMsg := fmt.Sprintf(msg, args...) fmt.Fprintf(os.Stderr, "[%s] [ERROR] [%s] %s\n", timestamp, l.name, logMsg) } // Debug logs debug messages to stdout (only if DEBUG env var is set) func (l *ContainerLogger) Debug(msg string, args ...interface{}) { if os.Getenv("DEBUG") != "" { timestamp := time.Now().UTC().Format("2006-01-02T15:04:05.000Z") logMsg := fmt.Sprintf(msg, args...) fmt.Fprintf(os.Stdout, "[%s] [DEBUG] [%s] %s\n", timestamp, l.name, logMsg) } }