Skip to content

Commit 1fea91b

Browse files
author
genejli
committed
update format function name
1 parent 62c9eda commit 1fea91b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

text_formatter.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"fmt"
66
"github.com/sirupsen/logrus"
7+
//"path/filepath"
78
"strconv"
89
"strings"
910
"time"
@@ -70,6 +71,13 @@ func defaultFormatFunc(funcName string) string {
7071
}
7172
return strings.Repeat(" ", FunctionNameLength-length) + funcName
7273
}
74+
func defaultFormatFuncTag(funcName string) string {
75+
idx := strings.LastIndex(funcName, "/")
76+
if -1 == idx {
77+
return funcName
78+
}
79+
return funcName[idx:]
80+
}
7381
func defaultFormatFile(fileName string) string {
7482
r := []rune(fileName)
7583
length := len(r)
@@ -188,6 +196,8 @@ func (f *TextFormatter) Format(entry *logrus.Entry) ([]byte, error) {
188196
function := entry.Caller.Function
189197
if f.FormatFuncName != nil {
190198
function = f.FormatFuncName(function)
199+
} else {
200+
function = defaultFormatFuncTag(function)
191201
}
192202
buf.WriteString(fmt.Sprintf(" (source=%v:%v:%v", fileName, function, entry.Caller.Line))
193203
}

0 commit comments

Comments
 (0)