Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
Make null logger a pointer type (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 authored and cw9 committed Oct 25, 2017
1 parent 2552847 commit 515e303
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ func (f Fields) ValueAt(i int) Field { return f[i] }
// NullLogger is a logger that emits nowhere.
var NullLogger Logger = nullLogger{}

type nullLogger struct {
fields Fields
}
type nullLogger struct{}

func (nullLogger) Enabled(_ Level) bool { return false }
func (nullLogger) Fatalf(msg string, args ...interface{}) {}
func (nullLogger) Fatalf(msg string, args ...interface{}) { os.Exit(1) }
func (nullLogger) Fatal(msg string) { os.Exit(1) }
func (nullLogger) Errorf(msg string, args ...interface{}) {}
func (nullLogger) Error(msg string) {}
Expand All @@ -140,23 +138,8 @@ func (nullLogger) Infof(msg string, args ...interface{}) {}
func (nullLogger) Info(msg string) {}
func (nullLogger) Debugf(msg string, args ...interface{}) {}
func (nullLogger) Debug(msg string) {}
func (l nullLogger) Fields() LoggerFields { return l.fields }

func (l nullLogger) WithFields(newFields ...Field) Logger {
existingLen := 0

existingFields := l.Fields()
if existingFields != nil {
existingLen = existingFields.Len()
}

fields := make([]Field, 0, existingLen+len(newFields))
for i := 0; i < existingLen; i++ {
fields = append(fields, existingFields.ValueAt(i))
}
fields = append(fields, newFields...)
return nullLogger{Fields(fields)}
}
func (l nullLogger) Fields() LoggerFields { return nil }
func (l nullLogger) WithFields(...Field) Logger { return l }

// SimpleLogger prints logging information to standard out.
var SimpleLogger = NewLogger(os.Stdout)
Expand Down

0 comments on commit 515e303

Please sign in to comment.