Skip to content

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

@moisesholguin

Description

@moisesholguin

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions