slog
A repo for slog
package main
import (
"errors"
"os"
"go.seankhliao.com/slog"
)
func main() {
l := slog.NewText(os.Stderr)
l.Info("hello", "foo", "bar")
l.Error(errors.New("an error"), "oops", "hello", "world")
l = slog.NewJSON(os.Stderr)
l.Info("hello", "foo", "bar")
l.Error(errors.New("an error"), "oops", "hello", "world")
http.Server{
Errorlog: slog.StdLogger(l),
}
}
output:
2020-10-12T21:46:13+02:00 INF msg="hello" foo="bar"
2020-10-12T21:46:13+02:00 ERR msg="oops" err="an error" hello="world"
{"time":"2020-10-12T21:46:13+02:00", "level":"INF", "msg":"hello", "foo":"bar"}
{"time":"2020-10-12T21:46:13+02:00", "level":"ERR", "msg":"oops", "err":"an error", "hello":"world"}