Skip to content

Commit

Permalink
add WithConfig (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktong authored May 17, 2024
1 parent 12c6d46 commit ef807d9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions gcp/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
"go.opentelemetry.io/otel/trace"
)

// Handler returns a slog.Handler integrated with [Cloud Logging] and [Cloud Error Reporting].
// Logger returns a slog.Logger which integrates with [Cloud Logging] and [Cloud Error Reporting].
//
// [Cloud Logging]: https://cloud.google.com/logging
// [Cloud Error Reporting]: https://cloud.google.com/error-reporting
func Handler(opts ...Option) slog.Handler {
func Logger(opts ...Option) *slog.Logger {
option := options{}
for _, opt := range opts {
opt(&option)
Expand Down Expand Up @@ -58,5 +58,5 @@ func Handler(opts ...Option) slog.Handler {
)
handler = otel.New(handler)

return handler
return slog.New(handler)
}
2 changes: 1 addition & 1 deletion gcp/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestLogHandler(t *testing.T) {
t.Parallel()

assert.NotNil(t, log.Handler(
assert.NotNil(t, log.Logger(
log.WithService("test"),
log.WithVersion("dev"),
log.WithProject("project"),
Expand Down
8 changes: 4 additions & 4 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func WithStopGate(gates ...func(context.Context) error) Option {
}
}

// WithLogHandler provides a slog.Handler to handle logs.
func WithLogHandler(handler slog.Handler) Option {
// WithLogger provides a slog.Logger to handle logs.
func WithLogger(logger *slog.Logger) Option {
return func(*options) {
slog.SetDefault(slog.New(handler))
slog.Info("Log handler has been initialized.")
slog.SetDefault(logger)
slog.Info("Logger has been initialized.")
}
}

Expand Down

0 comments on commit ef807d9

Please sign in to comment.