@cryptotaxi247 / kubo / commits / 67be6bbd5

skip logs when no writers connected

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Jun 17, 2015 at 11:05 UTC 67be6bbd571b511e3153c12994df627473a511f4
2 files changed +12
thirdparty/eventlog/log.go
+5
@@ -83,6 +83,11 @@ func (el *eventLogger) EventBegin(ctx context.Context, event string, metadata ..
83
84 func (el *eventLogger) Event(ctx context.Context, event string, metadata ...Loggable) {
85
86 + // short circuit if theres nothing to write to
87 + if !WriterGroup.Active() {
88 + return
89 + }
90 +
91 // Collect loggables for later logging
92 var loggables []Loggable
93
thirdparty/eventlog/writer.go
+7
@@ -29,3 +29,10 @@ func (mw *MirrorWriter) AddWriter(w io.Writer) {
29 mw.writers = append(mw.writers, w)
30 mw.lk.Unlock()
31 }
32 +
33 +func (mw *MirrorWriter) Active() (active bool) {
34 + mw.lk.Lock()
35 + active = len(mw.writers) > 0
36 + mw.lk.Unlock()
37 + return
38 +}