Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let user decide what to do if logger is not in context #175

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
)

var disabledLogger *Logger
var DefaultLogger *Logger

func init() {
l := Nop()
disabledLogger = &l
DefaultLogger = &l
}

type ctxKey struct{}
Expand Down Expand Up @@ -43,5 +43,5 @@ func Ctx(ctx context.Context) *Logger {
if l, ok := ctx.Value(ctxKey{}).(*Logger); ok {
return l
}
return disabledLogger
return DefaultLogger
}
2 changes: 1 addition & 1 deletion ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestCtx(t *testing.T) {
}

log2 = Ctx(context.Background())
if log2 != disabledLogger {
if log2 != DefaultLogger {
t.Error("Ctx did not return the expected logger")
}
}
Expand Down
2 changes: 1 addition & 1 deletion log.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (l Logger) With() Context {
//
// Use this method with caution. If unsure, prefer the With method.
func (l *Logger) UpdateContext(update func(c Context) Context) {
if l == disabledLogger {
if l == DefaultLogger {
return
}
if cap(l.context) == 0 {
Expand Down