iris
iris copied to clipboard
[FEATURE REQUEST] Support log/slog
Hello @trungdlp-wolffun, upgrade Iris with go get github.com/kataras/iris/v12@main and you can try Logger().Install method as shown below:
package main
import (
"log/slog"
"os"
"github.com/kataras/iris/v12"
)
func main() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
app := iris.New()
app.Logger().Install(logger)
// OR: app.Logger().Install(slog.Default())
}
Please post below if this is not suitable for your case.
This code does not work
Hello @lilili87222, what do you mean it doesn't work? I am able to verify it and it seems to be working, can you post me a full example to re-produce the issue please? Thanks a lot!
package main
import (
"log/slog"
"os"
"github.com/kataras/iris/v12"
)
func main() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
app := iris.New()
app.Logger().Install(logger)
// OR: app.Logger().Install(slog.Default())
app.Get("/", func(ctx iris.Context) {
ctx.Application().Logger().Infof("Request for path: %s", ctx.Path())
})
app.Listen(":8080")
}
This is because i was using go 1.9 witch doesn't has slog api