Skip to content

Commit

Permalink
feat: renamed WithSink option to WithSinks and changed it to be a var…
Browse files Browse the repository at this point in the history
…iadic function (instead of only accepting a string)
  • Loading branch information
zbindenren committed Dec 29, 2020
1 parent 82d61d1 commit e76679c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func WithoutCaller() Option {
}
}

// WithSink changes the default zap `stderr` sink.
func WithSink(name string) Option {
// WithSinks changes the default zap `stderr` sink.
func WithSinks(sinks ...string) Option {
return func(c *config) {
c.sink = name
c.sinks = sinks
}
}

Expand Down Expand Up @@ -110,8 +110,8 @@ func New(opts ...Option) *Logger {
zapConfig.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
}

if cfg.sink != "" {
zapConfig.OutputPaths = []string{cfg.sink}
if len(cfg.sinks) > 0 {
zapConfig.OutputPaths = cfg.sinks
}

var err error
Expand Down Expand Up @@ -212,5 +212,5 @@ type config struct {
disableStacktrace bool
isDebug bool
hook func(zapcore.Entry) error
sink string
sinks []string
}
16 changes: 8 additions & 8 deletions flash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestMain(m *testing.M) {
func TestDefault(t *testing.T) {
defer sink.Reset()

l := flash.New(flash.WithSink("memory://"))
l := flash.New(flash.WithSinks("memory://"))
l.Debug("debug")

e := sink.parse()
Expand All @@ -55,7 +55,7 @@ func TestDefault(t *testing.T) {
func TestWithColor(t *testing.T) {
defer sink.Reset()

l := flash.New(flash.WithSink("memory://"), flash.WithColor())
l := flash.New(flash.WithSinks("memory://"), flash.WithColor())

l.Info("info")

Expand All @@ -68,7 +68,7 @@ func TestWithColor(t *testing.T) {
func TestWithoutCaller(t *testing.T) {
defer sink.Reset()

l := flash.New(flash.WithSink("memory://"), flash.WithoutCaller())
l := flash.New(flash.WithSinks("memory://"), flash.WithoutCaller())
l.Info("info")
require.NotEmpty(t, sink.String())
e := sink.parse()
Expand All @@ -78,7 +78,7 @@ func TestWithoutCaller(t *testing.T) {
func TestWithStacktraceWithDebug(t *testing.T) {
defer sink.Reset()

l := flash.New(flash.WithSink("memory://"), flash.WithDebug(true), flash.WithStacktrace())
l := flash.New(flash.WithSinks("memory://"), flash.WithDebug(true), flash.WithStacktrace())
l.Info("info")
// only stacktraces for error in debug mode
assert.False(t, sink.containsStackTrace(), "stack trace detected")
Expand All @@ -89,7 +89,7 @@ func TestWithStacktraceWithDebug(t *testing.T) {
func TestSetDebugWithStacktrace(t *testing.T) {
defer sink.Reset()

l := flash.New(flash.WithSink("memory://"), flash.WithStacktrace())
l := flash.New(flash.WithSinks("memory://"), flash.WithStacktrace())
l.Debug("debug")
assert.Len(t, sink.String(), 0, "debug message logged")
l.Error("error")
Expand All @@ -111,7 +111,7 @@ func TestSetDebugWithStacktrace(t *testing.T) {
func TestDisable(t *testing.T) {
defer sink.Reset()

l := flash.New(flash.WithSink("memory://"))
l := flash.New(flash.WithSinks("memory://"))
l.Info("info")
assert.NotEmpty(t, sink.String(), 0)
sink.Reset()
Expand All @@ -125,7 +125,7 @@ func TestDisable(t *testing.T) {
func TestSetLevelWithStacktrace(t *testing.T) {
defer sink.Reset()

l := flash.New(flash.WithSink("memory://"), flash.WithStacktrace())
l := flash.New(flash.WithSinks("memory://"), flash.WithStacktrace())
l.Debug("debug")
assert.Empty(t, sink.String(), 0)
l.Error("error")
Expand All @@ -147,7 +147,7 @@ func TestWithPrometheus(t *testing.T) {

r := prometheus.NewRegistry()

l := flash.New(flash.WithSink("memory://"), flash.WithPrometheus("appname", r))
l := flash.New(flash.WithSinks("memory://"), flash.WithPrometheus("appname", r))

l.Info("info")
l.Info("info")
Expand Down

0 comments on commit e76679c

Please sign in to comment.