fix: use new sink api for logger package

This commit is contained in:
wpetit 2021-03-29 12:06:50 +02:00
parent 1c740f8399
commit 576d5f8548
4 changed files with 20 additions and 5 deletions

2
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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) {

13
logger/logger_test.go Normal file
View File

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