8000 Simplify stack helpers and remove internal/stack package by ChrisHines · Pull Request #11 · go-kit/log · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Simplify stack helpers and remove internal/stack package #11

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

Merged
merged 1 commit into from
Sep 17, 2021
Merged
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
38 changes: 0 additions & 38 deletions internal/stack/stack.go

This file was deleted.

31 changes: 27 additions & 4 deletions log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package log_test

import (
"bytes"
"runtime"
"sync"
"testing"

"github.com/go-kit/log"
"github.com/go-kit/log/internal/stack"
)

func TestContext(t *testing.T) {
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestWithPrefixAndSuffix(t *testing.T) {
// Valuers, regardless of how many times With has been called.
func TestContextStackDepth(t *testing.T) {
t.Parallel()
fn := stack.Caller(0).Function
fn := callingFunctions()[0]

var output []interface{}

Expand All @@ -118,8 +118,8 @@ func TestContextStackDepth(t *testing.T) {
}))

stackValuer := log.Valuer(func() interface{} {
for i, f := range stack.Trace() {
if f.Function == fn {
for i, f := range callingFunctions() {
if f == fn {
return i
}
}
Expand Down Expand Up @@ -149,6 +149,29 @@ func TestContextStackDepth(t *testing.T) {
}
}

// callingFunctions returns the names of the functions on the call stack for the
// current goroutine with element 0 identifying the calling function.
func callingFunctions() []string {
pcs := make([]uintptr, 10)
n := runtime.Callers(2, pcs)
if n == 0 {
return nil
}

frames := runtime.CallersFrames(pcs[:n])
funcs := make([]string, 0, n)

for {
frame, more := frames.Next()
funcs = append(funcs, frame.Function)
if !more {
break
}
}

return funcs
}

// Test that With returns a Logger safe for concurrent use. This test
// validates that the stored logging context does not get corrupted when
// multiple clients concurrently log additional keyvals.
Expand Down
0