[go-nuts] Re: [slog] customize defaultHandler

2023-08-29 Thread Tamás Gulácsi
Sorry for my wrong answer - I thought that should work. https://go.dev//issues/61892 explains it: the default slog handler uses the default log.Logger. This answers my other question, too: why is the default slog.Handler (newDefaultHandler) unexported? Because it's error prone. https://go.dev/p

Re: [go-nuts] Re: [slog] customize defaultHandler

2023-08-29 Thread Andrew Harris
Piping JSON output through jq is worth exploring. This much is enough to be nicer to human eyes: cat log.json | jq -c 'del(.time)' There's a nice Go implementation at https://github.com/itchyny/gojq. On Tuesday, August 29, 2023 at 12:59:55 AM UTC-7 Marcello H wrote: > After playing with it some

Re: [go-nuts] Re: [slog] customize defaultHandler

2023-08-29 Thread Marcello H
After playing with it some more: This also does the trick h := NewHandler(os.Stdout, &MyOptions{Level: slog.LevelDebug, TimeFormat: time.DateTime}) l := slog.New(h) slog.SetDefault(l) slog.Debug("hello") slog.Info("hello") slog.Warn("hello") slog.Error("hello") type MyOptions struct { // En

Re: [go-nuts] Re: [slog] customize defaultHandler

2023-08-29 Thread 'Sean Liao' via golang-nuts
cycle: https://go.dev//issues/61892 default handler, copied/exported: https://pkg.go.dev/github.com/jba/slog/handlers/loghandler - sean On Tue, Aug 29, 2023 at 7:53 AM Marcello H wrote: > Yesterday, I came up with the same question and found this: > "github.com/lmittmann/tint" > > (This solut

[go-nuts] Re: [slog] customize defaultHandler

2023-08-28 Thread Marcello H
Yesterday, I came up with the same question and found this: "github.com/lmittmann/tint" (This solution still uses os.Stdout, but I think this can do what you need.) An example: logOptions := &tint.Options{ NoColor: true, Level: slog.LevelError, TimeFormat: time.DateTime, } logHandler := tint.NewH

[go-nuts] Re: [slog] customize defaultHandler

2023-08-28 Thread Mike Schinkel
Hi Tamás, Have you actually tried that and gotten it to work? It does not compile for me but this does (note method call vs. property reference): slog.SetDefault(slog.New(myHandler{Handler:slog.Default().Handler()})) However, when delegating the Handle() method it seems to cause an infinite loop

[go-nuts] Re: [slog] customize defaultHandler

2023-08-28 Thread Tamás Gulácsi
slog.SetDefault(slog.New(myHandler{Handler:slog.Default().Handler})) vl...@mailbox.org a következőt írta (2023. augusztus 28., hétfő, 15:06:37 UTC+2): > Hi, > > When reading trough the log/slog documentation, it seems one can create > a logger with a different handler, which is either NewTextHa