Skip to content

Commit

Permalink
fixup! go-template/_template/internal/log: swapped zap logger with lo…
Browse files Browse the repository at this point in the history
…g/slog; added trace context handler; added gRPC interceptor logger
  • Loading branch information
zalgonoise committed Jul 18, 2024
1 parent 3872c0b commit 6ec59ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 11 additions & 0 deletions _template/internal/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ func New(opts ...Option) *slog.Logger {
return logger
}

// FromHandler initializes a logger with the provided slog.Handler interface.
//
// If the provided handler is nil, the function returns a no-op slog.Logger.
func FromHandler(handler slog.Handler) *slog.Logger {
if handler == nil {
return NoOp()
}

return slog.New(NewSpanContextHandler(handler, true))
}

func NoOp() *slog.Logger {
return slog.New(noOpHandler{})
}
Expand Down
10 changes: 0 additions & 10 deletions _template/internal/log/logger_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ func (o OptionFunc) apply(c *Config) {
o(c)
}

func WithHandler(handler slog.Handler) OptionFunc {
if handler == nil {
return func(*Config) {}
}

return func(config *Config) {
config.handler = handler
}
}

func WithWriter(writer io.Writer) OptionFunc {
if writer == nil {
return func(*Config) {}
Expand Down

0 comments on commit 6ec59ce

Please sign in to comment.