Skip to content

Commit

Permalink
leveled: fix default logger and add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
justinruggles committed Sep 11, 2019
1 parent 93b8bdd commit 6e7f81d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
10 changes: 5 additions & 5 deletions leveled/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,30 @@ func Default(logger *alog.Logger) Logger {

// Debug implements Logger.Debug
func (d *defaultLogger) Debug(ctx context.Context, f string, v ...interface{}) {
alog.AddTags(ctx, "level", "debug")
ctx = alog.AddTags(ctx, "level", "debug")
d.Logger.Output(ctx, 3, fmt.Sprintf(f, v...))
}

// Info implements Logger.Info
func (d *defaultLogger) Info(ctx context.Context, f string, v ...interface{}) {
alog.AddTags(ctx, "level", "info")
ctx = alog.AddTags(ctx, "level", "info")
d.Logger.Output(ctx, 3, fmt.Sprintf(f, v...))
}

// Warning implements Logger.Warning
func (d *defaultLogger) Warning(ctx context.Context, f string, v ...interface{}) {
alog.AddTags(ctx, "level", "warning")
ctx = alog.AddTags(ctx, "level", "warning")
d.Logger.Output(ctx, 3, fmt.Sprintf(f, v...))
}

// Error implements Logger.Error
func (d *defaultLogger) Error(ctx context.Context, f string, v ...interface{}) {
alog.AddTags(ctx, "level", "error")
ctx = alog.AddTags(ctx, "level", "error")
d.Logger.Output(ctx, 3, fmt.Sprintf(f, v...))
}

// Critical implements Logger.Critical
func (d *defaultLogger) Critical(ctx context.Context, f string, v ...interface{}) {
alog.AddTags(ctx, "level", "critical")
ctx = alog.AddTags(ctx, "level", "critical")
d.Logger.Output(ctx, 3, fmt.Sprintf(f, v...))
}
23 changes: 23 additions & 0 deletions leveled/logger_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package leveled

import (
"bytes"
"context"
"testing"

"github.com/vimeo/alog/v3"
"github.com/vimeo/alog/v3/emitter/textlog"
)

func TestLogger(t *testing.T) {
b := &bytes.Buffer{}
l := Default(alog.New(alog.WithEmitter(textlog.Emitter(b))))

ctx := context.Background()
ctx = alog.AddTags(ctx, "key", "value")
l.Info(ctx, "")
const want = `[key=value level=info] ` + "\n"
if got := b.String(); got != want {
t.Errorf("got: %#q, want: %#q", got, want)
}
}

0 comments on commit 6e7f81d

Please sign in to comment.