Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zapslog: rename Option to HandlerOption #1411

Merged
merged 2 commits into from Feb 6, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion exp/zapslog/handler.go
Expand Up @@ -50,7 +50,7 @@ type Handler struct {

// NewHandler builds a [Handler] that writes to the supplied [zapcore.Core]
// with options.
func NewHandler(core zapcore.Core, opts ...Option) *Handler {
func NewHandler(core zapcore.Core, opts ...HandlerOption) *Handler {
h := &Handler{
core: core,
addStackAt: slog.LevelError,
Expand Down
26 changes: 13 additions & 13 deletions exp/zapslog/options.go
Expand Up @@ -24,29 +24,29 @@ package zapslog

import "log/slog"

// An Option configures a slog Handler.
type Option interface {
// An HandlerOption configures a slog Handler.
abhinav marked this conversation as resolved.
Show resolved Hide resolved
type HandlerOption interface {
apply(*Handler)
}

// optionFunc wraps a func so it satisfies the Option interface.
type optionFunc func(*Handler)
// handlerOptionFunc wraps a func so it satisfies the Option interface.
type handlerOptionFunc func(*Handler)

func (f optionFunc) apply(handler *Handler) {
func (f handlerOptionFunc) apply(handler *Handler) {
f(handler)
}

// WithName configures the Logger to annotate each message with the logger name.
func WithName(name string) Option {
return optionFunc(func(h *Handler) {
func WithName(name string) HandlerOption {
return handlerOptionFunc(func(h *Handler) {
h.name = name
})
}

// WithCaller configures the Logger to include the filename and line number
// of the caller in log messages--if available.
func WithCaller(enabled bool) Option {
return optionFunc(func(handler *Handler) {
func WithCaller(enabled bool) HandlerOption {
return handlerOptionFunc(func(handler *Handler) {
handler.addCaller = enabled
})
}
Expand All @@ -57,16 +57,16 @@ func WithCaller(enabled bool) Option {
// When building wrappers around the Logger,
// supplying this Option prevents Zap from always reporting
// the wrapper code as the caller.
func WithCallerSkip(skip int) Option {
return optionFunc(func(log *Handler) {
func WithCallerSkip(skip int) HandlerOption {
return handlerOptionFunc(func(log *Handler) {
log.callerSkip += skip
})
}

// AddStacktraceAt configures the Logger to record a stack trace
// for all messages at or above a given level.
func AddStacktraceAt(lvl slog.Level) Option {
return optionFunc(func(log *Handler) {
func AddStacktraceAt(lvl slog.Level) HandlerOption {
return handlerOptionFunc(func(log *Handler) {
log.addStackAt = lvl
})
}