Skip to content

Commit

Permalink
Remove enabled function (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
oibe authored and akshayjshah committed Jun 22, 2016
1 parent 0adf805 commit 37b4c8e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 33 deletions.
10 changes: 2 additions & 8 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ var _exit = os.Exit
// A Logger enables leveled, structured logging. All methods are safe for
// concurrent use.
type Logger interface {
// Check if output at a specific level is enabled.
Enabled(Level) bool
// Check the minimum enabled log level.
Level() Level
// Change the level of this logger, as well as all its ancestors and
Expand Down Expand Up @@ -117,10 +115,6 @@ func (jl *jsonLogger) SetLevel(lvl Level) {
jl.level.Store(int32(lvl))
}

func (jl *jsonLogger) Enabled(lvl Level) bool {
return lvl >= jl.Level()
}

func (jl *jsonLogger) With(fields ...Field) Logger {
clone := &jsonLogger{
level: jl.level,
Expand All @@ -142,7 +136,7 @@ func (jl *jsonLogger) StubTime() {
}

func (jl *jsonLogger) Check(lvl Level, msg string) *CheckedMessage {
if !jl.Enabled(lvl) {
if !(lvl >= jl.Level()) {
return nil
}
return NewCheckedMessage(jl, lvl, msg)
Expand Down Expand Up @@ -193,7 +187,7 @@ func (jl *jsonLogger) DFatal(msg string, fields ...Field) {
}

func (jl *jsonLogger) log(lvl Level, msg string, fields []Field) {
if !jl.Enabled(lvl) {
if !(lvl >= jl.Level()) {
return
}

Expand Down
18 changes: 0 additions & 18 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,6 @@ func TestJSONLoggerSetLevel(t *testing.T) {
})
}

func TestJSONLoggerEnabled(t *testing.T) {
withJSONLogger(t, opts(InfoLevel), func(jl *jsonLogger, _ func() []string) {
assert.False(t, jl.Enabled(DebugLevel), "Debug logs shouldn't be enabled at Info level.")
assert.True(t, jl.Enabled(InfoLevel), "Info logs should be enabled at Info level.")
assert.True(t, jl.Enabled(WarnLevel), "Warn logs should be enabled at Info level.")
assert.True(t, jl.Enabled(ErrorLevel), "Error logs should be enabled at Info level.")
assert.True(t, jl.Enabled(PanicLevel), "Panic logs should be enabled at Info level.")
assert.True(t, jl.Enabled(FatalLevel), "Fatal logs should be enabled at Info level.")

for _, lvl := range []Level{DebugLevel, InfoLevel, WarnLevel, ErrorLevel, PanicLevel, FatalLevel} {
jl.SetLevel(NoneLevel)
assert.False(t, jl.Enabled(lvl), "No logging should be enabled at None level.")
jl.SetLevel(AllLevel)
assert.True(t, jl.Enabled(lvl), "All logging should be enabled at All level.")
}
})
}

func TestJSONLoggerConcurrentLevelMutation(t *testing.T) {
// Trigger races for non-atomic level mutations.
proceed := make(chan struct{})
Expand Down
7 changes: 1 addition & 6 deletions spy/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ func (l *Logger) SetDevelopment(dev bool) {
l.Unlock()
}

// Enabled checks whether logging at the specified level is enabled.
func (l *Logger) Enabled(lvl zap.Level) bool {
return lvl >= l.Level()
}

// Level returns the currently-enabled logging level.
func (l *Logger) Level() zap.Level {
l.Lock()
Expand Down Expand Up @@ -124,7 +119,7 @@ func (l *Logger) With(fields ...zap.Field) zap.Logger {

// Check returns a CheckedMessage if logging a particular message would succeed.
func (l *Logger) Check(lvl zap.Level, msg string) *zap.CheckedMessage {
if !l.Enabled(lvl) {
if !(lvl >= l.Level()) {
return nil
}
return zap.NewCheckedMessage(l, lvl, msg)
Expand Down
2 changes: 1 addition & 1 deletion zwrap/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (s *sampler) DFatal(msg string, fields ...zap.Field) {
}

func (s *sampler) check(lvl zap.Level, msg string) bool {
if !s.Enabled(lvl) {
if !(lvl >= s.Level()) {
return false
}
n := s.counts.Inc(msg)
Expand Down

0 comments on commit 37b4c8e

Please sign in to comment.