Commit 880709a6 authored by Matthew Sykes's avatar Matthew Sykes
Browse files

[FAB-13591] reduce scope of rlock around observer



Change-Id: I7ea50a583b0af311b02366a1e5124dd9faedf380
Signed-off-by: default avatarMatthew Sykes <sykesmat@us.ibm.com>
parent e51851a3
......@@ -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.
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment