iris icon indicating copy to clipboard operation
iris copied to clipboard

[FEATURE REQUEST] Support log/slog

Open trungdlp-wolffun opened this issue 2 years ago • 4 comments

trungdlp-wolffun avatar Oct 25 '23 10:10 trungdlp-wolffun

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.

kataras avatar Nov 01 '23 18:11 kataras

This code does not work

lilili87222 avatar Dec 08 '23 10:12 lilili87222

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")
}

image

kataras avatar Dec 25 '23 22:12 kataras

This is because i was using go 1.9 witch doesn't has slog api

lilili87222 avatar Feb 13 '24 15:02 lilili87222