Skip to content

Commit

Permalink
feat: better logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ConsoleTVs committed Jul 11, 2024
1 parent 0b2a8ac commit 22d2846
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ import (
"github.com/studiolambda/akumu"
)

func Logger(handler http.Handler, logger *slog.Logger) http.Handler {
func Logger(logger *slog.Logger) func(http.Handler) http.Handler {
return func(handler http.Handler) http.Handler {
return LoggerWith(handler, logger)
}
}

func LoggerDefault() func(http.Handler) http.Handler {
return func(handler http.Handler) http.Handler {
return LoggerWith(handler, slog.Default())
}
}

func LoggerWith(handler http.Handler, logger *slog.Logger) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
handler.ServeHTTP(writer, request.WithContext(
context.WithValue(request.Context(), akumu.LoggerKey{}, logger),
Expand Down

0 comments on commit 22d2846

Please sign in to comment.