Skip to content

Commit

Permalink
chore: improve slog (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq authored Sep 9, 2024
1 parent 1923c84 commit 9f1afed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ tasks:
test:
cmd: |
GOEXPERIMENT=nocoverageredesign go test -race -cover -coverprofile=coverage.out \
PATH=$PATH:$GOBIN GOEXPERIMENT=nocoverageredesign go test -race -cover -coverprofile=coverage.out \
-covermode=atomic ./... ./tests/... \
-coverpkg .,./cmd/...,./internal/...,./interceptor/...
git checkout tests/case1/kod_gen_mock.go
Expand Down
11 changes: 6 additions & 5 deletions kod.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,15 @@ func (k *Kod) configureLog(ctx context.Context, res *sdkresource.Resource) {

// newSlog creates a new slog logger with the provided handler.
func (k *Kod) newSlog(handler slog.Handler) *slog.Logger {
var logger *slog.Logger

if k.opts.logger != nil {
return k.opts.logger
logger = k.opts.logger
} else {
handler = kslog.NewLevelHandler(k.config.LogLevel)(handler)
logger = slog.New(handler)
}

handler = kslog.NewLevelHandler(k.config.LogLevel)(handler)

logger := slog.New(handler)

slog.SetDefault(logger)

return logger
Expand Down

0 comments on commit 9f1afed

Please sign in to comment.