Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] Support log/slog #2260

Open
trungdlp-wolffun opened this issue Oct 25, 2023 · 4 comments
Open

[FEATURE REQUEST] Support log/slog #2260

trungdlp-wolffun opened this issue Oct 25, 2023 · 4 comments
Assignees

Comments

@trungdlp-wolffun
Copy link
Contributor

No description provided.

@kataras
Copy link
Owner

kataras commented Nov 1, 2023

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.

@lilili87222
Copy link

This code does not work

@kataras
Copy link
Owner

kataras commented Dec 25, 2023

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

@lilili87222
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@lilili87222 @kataras @trungdlp-wolffun and others