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

correctly display the line number when FinishWithErr fails #51

Merged
merged 1 commit into from
Oct 3, 2018
Merged
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
10 changes: 7 additions & 3 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ func (el *eventLogger) SetTags(ctx context.Context, tags map[string]interface{})
}
}

func (el *eventLogger) SetErr(ctx context.Context, err error) {
func (el *eventLogger) setErr(ctx context.Context, err error, skip int) {
span := opentrace.SpanFromContext(ctx)
if span == nil {
_, file, line, _ := runtime.Caller(1)
_, file, line, _ := runtime.Caller(skip)
log.Errorf("SetErr with no Span in context called on %s:%d", path.Base(file), line)
return
}
Expand All @@ -243,6 +243,10 @@ func (el *eventLogger) SetErr(ctx context.Context, err error) {
span.LogKV("error", err.Error())
}

func (el *eventLogger) SetErr(ctx context.Context, err error) {
el.setErr(ctx, err, 1)
}

func (el *eventLogger) Finish(ctx context.Context) {
span := opentrace.SpanFromContext(ctx)
if span == nil {
Expand All @@ -254,7 +258,7 @@ func (el *eventLogger) Finish(ctx context.Context) {
}

func (el *eventLogger) FinishWithErr(ctx context.Context, err error) {
el.SetErr(ctx, err)
el.setErr(ctx, err, 2)
el.Finish(ctx)
}

Expand Down