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

Add slog based logger #59

Open
sagikazarmark opened this issue Aug 7, 2024 · 0 comments
Open

Add slog based logger #59

sagikazarmark opened this issue Aug 7, 2024 · 0 comments

Comments

@sagikazarmark
Copy link
Contributor

Since there is a structured logger in the Go stdlib now, we could add something like this to this package too:

package gosundheit

import (
	"log/slog"

	health "github.com/AppsFlyer/go-sundheit"
)

type checkListener struct {
	logger *slog.Logger
}

func NewLogger(logger *slog.Logger) health.CheckListener {
	return checkListener{
		logger: logger,
	}
}

func (c checkListener) OnCheckRegistered(name string, result health.Result) {
	if result.Error != nil {
		c.logger.Error("initial health check failed", slog.String("check", name), slog.Any("error", result.Error))

		return
	}

	c.logger.Debug("health check registered", slog.String("check", name))
}

func (c checkListener) OnCheckStarted(name string) {
	c.logger.Debug("starting health check", slog.String("check", name))
}

func (c checkListener) OnCheckCompleted(name string, result health.Result) {
	if result.Error != nil {
		c.logger.Error("health check failed", slog.String("check", name), slog.Any("error", result.Error))

		return
	}

	c.logger.Debug("health check completed", slog.String("check", name))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant