Skip to content

Commit

Permalink
Merge "[FAB-13591] reduce scope of rlock around observer" into releas…
Browse files Browse the repository at this point in the history
…e-1.4
  • Loading branch information
denyeart authored and Gerrit Code Review committed Jan 11, 2019
2 parents 56dfcad + 880709a commit ec8d9ea
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions common/flogging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ func (s *Logging) SetWriter(w io.Writer) {
s.mutex.Unlock()
}

// SetObserver is used to provide a log observer that will be called as log
// levels are checked or written.. Only a single observer is supported.
func (s *Logging) SetObserver(observer Observer) {
s.mutex.Lock()
s.observer = observer
s.mutex.Unlock()
}

// Write satisfies the io.Write contract. It delegates to the writer argument
// of SetWriter or the Writer field of Config. The Core uses this when encoding
// log records.
Expand Down Expand Up @@ -218,24 +226,22 @@ func (s *Logging) ZapLogger(name string) *zap.Logger {

func (s *Logging) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) {
s.mutex.RLock()
if s.observer != nil {
s.observer.Check(e, ce)
}
observer := s.observer
s.mutex.RUnlock()

if observer != nil {
observer.Check(e, ce)
}
}

func (s *Logging) WriteEntry(e zapcore.Entry, fields []zapcore.Field) {
s.mutex.RLock()
if s.observer != nil {
s.observer.WriteEntry(e, fields)
}
observer := s.observer
s.mutex.RUnlock()
}

func (s *Logging) SetObserver(observer Observer) {
s.mutex.Lock()
s.observer = observer
s.mutex.Unlock()
if observer != nil {
observer.WriteEntry(e, fields)
}
}

// Logger instantiates a new FabricLogger with the specified name. The name is
Expand Down

0 comments on commit ec8d9ea

Please sign in to comment.