Skip to content

Commit 7db06bc

Browse files
authored
zapslog: rename Option to HandlerOption (#1411)
Refs #1333 Rename `Option` to `HandlerOption` to avoid future conflicts with [zap.Option](https://pkg.go.dev/go.uber.org/zap#Option). There is no change in functionality. This is a breaking change to zapslog, but the package is currently marked experimental. This will allow us to stabilize it. --------- Signed-off-by: junya koyama <[email protected]>
1 parent 35ded09 commit 7db06bc

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

exp/zapslog/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Handler struct {
5050

5151
// NewHandler builds a [Handler] that writes to the supplied [zapcore.Core]
5252
// with options.
53-
func NewHandler(core zapcore.Core, opts ...Option) *Handler {
53+
func NewHandler(core zapcore.Core, opts ...HandlerOption) *Handler {
5454
h := &Handler{
5555
core: core,
5656
addStackAt: slog.LevelError,

exp/zapslog/options.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ package zapslog
2424

2525
import "log/slog"
2626

27-
// An Option configures a slog Handler.
28-
type Option interface {
27+
// A HandlerOption configures a slog Handler.
28+
type HandlerOption interface {
2929
apply(*Handler)
3030
}
3131

32-
// optionFunc wraps a func so it satisfies the Option interface.
33-
type optionFunc func(*Handler)
32+
// handlerOptionFunc wraps a func so it satisfies the Option interface.
33+
type handlerOptionFunc func(*Handler)
3434

35-
func (f optionFunc) apply(handler *Handler) {
35+
func (f handlerOptionFunc) apply(handler *Handler) {
3636
f(handler)
3737
}
3838

3939
// WithName configures the Logger to annotate each message with the logger name.
40-
func WithName(name string) Option {
41-
return optionFunc(func(h *Handler) {
40+
func WithName(name string) HandlerOption {
41+
return handlerOptionFunc(func(h *Handler) {
4242
h.name = name
4343
})
4444
}
4545

4646
// WithCaller configures the Logger to include the filename and line number
4747
// of the caller in log messages--if available.
48-
func WithCaller(enabled bool) Option {
49-
return optionFunc(func(handler *Handler) {
48+
func WithCaller(enabled bool) HandlerOption {
49+
return handlerOptionFunc(func(handler *Handler) {
5050
handler.addCaller = enabled
5151
})
5252
}
@@ -57,16 +57,16 @@ func WithCaller(enabled bool) Option {
5757
// When building wrappers around the Logger,
5858
// supplying this Option prevents Zap from always reporting
5959
// the wrapper code as the caller.
60-
func WithCallerSkip(skip int) Option {
61-
return optionFunc(func(log *Handler) {
60+
func WithCallerSkip(skip int) HandlerOption {
61+
return handlerOptionFunc(func(log *Handler) {
6262
log.callerSkip += skip
6363
})
6464
}
6565

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

0 commit comments

Comments
 (0)