From 576d5f8548a3c312614786212b325cd270a6f7d6 Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 29 Mar 2021 12:06:50 +0200 Subject: [PATCH] fix: use new sink api for logger package --- go.mod | 2 +- go.sum | 2 ++ logger/logger.go | 8 ++++---- logger/logger_test.go | 13 +++++++++++++ 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 logger/logger_test.go diff --git a/go.mod b/go.mod index 99ca0d9..26b9b80 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module gitlab.com/wpetit/goweb go 1.12 require ( - cdr.dev/slog v1.3.0 + cdr.dev/slog v1.4.0 github.com/go-chi/chi v4.0.2+incompatible github.com/go-playground/locales v0.12.1 // indirect github.com/go-playground/universal-translator v0.16.0 // indirect diff --git a/go.sum b/go.sum index c2095e8..fe8bea8 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ cdr.dev/slog v1.3.0 h1:MYN1BChIaVEGxdS7I5cpdyMC0+WfJfK8BETAfzfLUGQ= cdr.dev/slog v1.3.0/go.mod h1:C5OL99WyuOK8YHZdYY57dAPN1jK2WJlCdq2VP6xeQns= +cdr.dev/slog v1.4.0 h1:tLXQJ/hZ5Q051h0MBHSd2Ha8xzdXj7CjtzmG/8dUvUk= +cdr.dev/slog v1.4.0/go.mod h1:C5OL99WyuOK8YHZdYY57dAPN1jK2WJlCdq2VP6xeQns= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= diff --git a/logger/logger.go b/logger/logger.go index 5472aba..604e170 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -40,18 +40,18 @@ func init() { // nolint: gochecknoinits } func Make(f Format, w io.Writer) slog.Logger { - var logger slog.Logger + var sink slog.Sink switch f { case FormatHuman: - logger = sloghuman.Make(w) + sink = sloghuman.Sink(w) case FormatJSON: - logger = slogjson.Make(w) + sink = slogjson.Sink(w) default: panic(errors.Errorf("unknown logger format '%s'", f)) } - return logger + return slog.Make(sink) } func Debug(ctx context.Context, msg string, fields ...Field) { diff --git a/logger/logger_test.go b/logger/logger_test.go new file mode 100644 index 0000000..238841e --- /dev/null +++ b/logger/logger_test.go @@ -0,0 +1,13 @@ +package logger + +import ( + "context" + "os" + "testing" +) + +func TestLogger(t *testing.T) { + log := Make(FormatHuman, os.Stdout) + + log.Info(context.Background(), "test") +}