Merge pull request #18 from aaronlehmann/avoid-logging-sink

Don't include serialization of sink in log messages
This commit is contained in:
Stephen Day 2016-08-26 16:13:32 -04:00 коммит произвёл GitHub
Родитель 23780caac6 5110791f2d
Коммит a7969c8a34
3 изменённых файлов: 44 добавлений и 1 удалений

Просмотреть файл

@ -1,6 +1,7 @@
package events
import (
"fmt"
"sync"
"github.com/Sirupsen/logrus"
@ -158,3 +159,20 @@ func (b *Broadcaster) run() {
}
}
}
func (b Broadcaster) String() string {
// Serialize copy of this broadcaster without the sync.once, to avoid
// a data race.
b2 := Broadcaster{
sinks: b.sinks,
events: b.events,
adds: b.adds,
removes: b.removes,
shutdown: b.shutdown,
closed: b.closed,
}
return fmt.Sprint(b2)
}

Просмотреть файл

@ -1,6 +1,9 @@
package events
import "sync"
import (
"fmt"
"sync"
)
// Channel provides a sink that can be listened on. The writer and channel
// listener must operate in separate goroutines.
@ -46,3 +49,13 @@ func (ch *Channel) Close() error {
return nil
}
func (ch Channel) String() string {
// Serialize a copy of the Channel that doesn't contain the sync.Once,
// to avoid a data race.
ch2 := Channel{
C: ch.C,
closed: ch.closed,
}
return fmt.Sprint(ch2)
}

Просмотреть файл

@ -1,6 +1,7 @@
package events
import (
"fmt"
"math/rand"
"sync"
"sync/atomic"
@ -89,6 +90,17 @@ func (rs *RetryingSink) Close() error {
return nil
}
func (rs RetryingSink) String() string {
// Serialize a copy of the RetryingSink without the sync.Once, to avoid
// a data race.
rs2 := RetryingSink{
sink: rs.sink,
strategy: rs.strategy,
closed: rs.closed,
}
return fmt.Sprint(rs2)
}
// RetryStrategy defines a strategy for retrying event sink writes.
//
// All methods should be goroutine safe.