Skip to content

Panic on nil *time.Time value #85

@rollulus

Description

@rollulus
func main() {
	jsonLog := slog.New(slog.NewJSONHandler(os.Stdout, nil))
	textLog := slog.New(slog.NewTextHandler(os.Stdout, nil))
	tintLog := slog.New(tint.NewHandler(os.Stdout, nil))

	var t *time.Time
	jsonLog.Info("Hello", "t", t) // Fine.
	textLog.Info("Hello", "t", t) // Fine.
	tintLog.Info("Hello", "t", t) // panic: value method time.Time.MarshalText called using nil *Time pointer
}

https://go.dev/play/p/UAi6SlyJJnQ

This makes tint not a drop-in alternative for the common slog handlers. My understanding is that slog handles this case as follows: https://github.com/golang/go/blob/master/src/log/slog/handler.go#L558

Thanks for tint. A bit of colour in our dull backend world is nice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions