Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/go-coldbrew/errors v0.2.14
github.com/go-coldbrew/hystrixprometheus v0.1.2
github.com/go-coldbrew/interceptors v0.1.24
github.com/go-coldbrew/log v0.3.2
github.com/go-coldbrew/log v0.4.0
github.com/go-coldbrew/options v0.3.0
Comment thread
ankurs marked this conversation as resolved.
github.com/go-coldbrew/tracing v0.2.2
github.com/golang/protobuf v1.5.4
Expand Down
10 changes: 4 additions & 6 deletions initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/go-coldbrew/interceptors"
"github.com/go-coldbrew/log"
"github.com/go-coldbrew/log/loggers"
cbslog "github.com/go-coldbrew/log/loggers/slog"
nrutil "github.com/go-coldbrew/tracing/newrelic"
protov1 "github.com/golang/protobuf/proto" //nolint:staticcheck
newrelic "github.com/newrelic/go-agent/v3/newrelic"
Expand Down Expand Up @@ -67,19 +66,18 @@ func SetupNewRelic(serviceName, apiKey string, tracing bool) error {
return nil
}

// SetupLogger sets up the logger
// It uses the coldbrew logger to log messages to stdout
// SetupLogger sets up the logger using ColdBrew's slog-native Handler.
// It calls log.SetDefault which also wires slog.SetDefault, so native
// slog.LogAttrs calls automatically get ColdBrew context fields.
// logLevel is the log level to set for the logger
// jsonlogs is a boolean to enable or disable json logs
func SetupLogger(logLevel string, jsonlogs bool) error {
log.SetLogger(log.NewLogger(cbslog.NewLogger(loggers.WithJSONLogs(jsonlogs))))

ll, err := loggers.ParseLevel(logLevel)
if err != nil {
log.Error(context.Background(), "err", "could not set log level", "level", logLevel)
Comment thread
ankurs marked this conversation as resolved.
Outdated
return err
}
log.SetLevel(ll)
log.SetDefault(log.NewHandler(loggers.WithJSONLogs(jsonlogs), loggers.WithLevel(ll)))
return nil
Comment thread
ankurs marked this conversation as resolved.
}

Expand Down
Loading