charmbracelet / log

A minimal, colorful Go logging library 🪵
MIT License
2.4k stars 67 forks source link

Passing a logger instance to Slog is not respecting TimeFunction #114

Closed moisesholguin closed 8 months ago

moisesholguin commented 8 months ago

main.go

package main

import (
    "fmt"
    "log/slog"
    "os"
    "time"

    "github.com/charmbracelet/log"
)

func main() {
    // baseline
    fmt.Println(time.Now().UTC().Format(time.RFC3339), "foo")
    fmt.Println(time.Now().Format(time.RFC3339), "foo")

    handler := log.NewWithOptions(os.Stdout, log.Options{
        ReportTimestamp: true,
        TimeFunction:    log.NowUTC,
        TimeFormat:      time.RFC3339,
    })
    handler.Info("foo") // UTC

    logger := slog.New(handler)
    logger.Info("foo") // not UTC
}

Output

$ go version
go version go1.22.0 darwin/arm64
$ go run ./main.go
2024-03-19T21:31:25Z foo
2024-03-19T14:31:25-07:00 foo
2024-03-19T21:31:25Z INFO foo
2024-03-19T14:31:25-07:00 INFO foo