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

Remove goroutine ID field from logger #977

Merged
merged 1 commit into from
Jul 18, 2023
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
17 changes: 2 additions & 15 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io/ioutil"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -98,9 +97,8 @@ func (l *Logger) Logf(level logrus.Level, category string, msg string, args ...a
return
}
fields := logrus.Fields{
"category": category,
"elapsed": fmt.Sprintf("%d ms", elapsed),
"goroutine": goRoutineID(),
"category": category,
"elapsed": fmt.Sprintf("%d ms", elapsed),
}
if l.iterID != "" && l.GetLevel() > logrus.InfoLevel {
fields["iteration_id"] = l.iterID
Expand Down Expand Up @@ -176,17 +174,6 @@ func (l *Logger) SetCategoryFilter(filter string) (err error) {
return nil
}

func goRoutineID() int {
var buf [64]byte
n := runtime.Stack(buf[:], false)
idField := strings.Fields(strings.TrimPrefix(string(buf[:n]), "goroutine "))[0]
id, err := strconv.Atoi(idField)
if err != nil {
panic(fmt.Sprintf("internal error while getting goroutine ID: %v", err))
}
return id
}

type consoleLogFormatter struct {
logrus.Formatter
}
Expand Down