Skip to content

Commit

Permalink
update implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-carlton committed Oct 26, 2024
1 parent 194ce96 commit 14fa32c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
Expand Down Expand Up @@ -181,21 +182,26 @@ func setSourceName(a slog.Attr) slog.Attr {
return a
}

// NewLogger returns a JSON logger.
func NewLogger() *slog.Logger {
opts := &slog.HandlerOptions{
// NewLogger returns a JSON logger writing to provided writer.
func NewLoggerTo(out io.Writer) *slog.Logger {
return slog.New(slog.NewJSONHandler(out, setupOptions()))
}

func setupOptions() *slog.HandlerOptions {
return &slog.HandlerOptions{
Level: LogLevel,
AddSource: logSource,
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { //nolint: revive
a = setLogLevelName(a)
a = setSourceName(a)
return a
},
}

handler := slog.NewJSONHandler(os.Stdout, opts)
}
}

return slog.New(handler)
// NewLogger returns a JSON logger.
func NewLogger() *slog.Logger {
return slog.New(slog.NewJSONHandler(os.Stdout, setupOptions()))
}

// traceLogger returns a logger for internal use by tracing that replaces the source details with supplied values.
Expand Down

0 comments on commit 14fa32c

Please sign in to comment.