Skip to content

Commit

Permalink
Keep some auto-locking
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay Shah committed Mar 13, 2017
1 parent 4be34c6 commit f2a590e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func (cfg Config) Build(opts ...Option) (*Logger, error) {
}

log := New(
zapcore.NewCore(enc, zapcore.Lock(sink), cfg.Level),
cfg.buildOptions(zapcore.Lock(errSink))...,
zapcore.NewCore(enc, sink, cfg.Level),
cfg.buildOptions(errSink)...,
)
if len(opts) > 0 {
log = log.WithOptions(opts...)
Expand Down
6 changes: 4 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ func Fields(fs ...zapcore.Field) Option {
}

// ErrorOutput sets the destination for errors generated by the logger. The
// supplied WriteSyncer is automatically wrapped with a mutex, so it need not be
// safe for concurrent use.
// supplied WriteSyncer must be safe for concurrent use.
//
// The Open and zapcore.Lock functions are the simplest ways to make files safe
// for concurrent use.
func ErrorOutput(w zapcore.WriteSyncer) Option {
return optionFunc(func(log *Logger) {
log.errorOutput = w
Expand Down
4 changes: 2 additions & 2 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func open(paths []string) ([]zapcore.WriteSyncer, func(), error) {
return writers, close, errs.AsError()
}

// CombineWriteSyncers combines the passed set of WriteSyncer objects into a
// CombineWriteSyncers combines the passed set of WriteSyncers into a single
// locked WriteSyncer.
func CombineWriteSyncers(writers ...zapcore.WriteSyncer) zapcore.WriteSyncer {
if len(writers) == 0 {
return zapcore.AddSync(ioutil.Discard)
}
return zapcore.NewMultiWriteSyncer(writers...)
return zapcore.Lock(zapcore.NewMultiWriteSyncer(writers...))
}

0 comments on commit f2a590e

Please sign in to comment.