skip logs when no writers connected

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy 2015-06-17 11:05:31 -07:00
parent 90896f283f
commit 67be6bbd57
2 changed files with 12 additions and 0 deletions

View File

@ -83,6 +83,11 @@ func (el *eventLogger) EventBegin(ctx context.Context, event string, metadata ..
func (el *eventLogger) Event(ctx context.Context, event string, metadata ...Loggable) {
// short circuit if theres nothing to write to
if !WriterGroup.Active() {
return
}
// Collect loggables for later logging
var loggables []Loggable

View File

@ -29,3 +29,10 @@ func (mw *MirrorWriter) AddWriter(w io.Writer) {
mw.writers = append(mw.writers, w)
mw.lk.Unlock()
}
func (mw *MirrorWriter) Active() (active bool) {
mw.lk.Lock()
active = len(mw.writers) > 0
mw.lk.Unlock()
return
}