Skip to content

Commit

Permalink
feat(log): add function name and line number in log message
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn 5509

Signed-off-by: Jack Lin <[email protected]>
  • Loading branch information
ChanYiLin authored and David Ko committed Oct 23, 2023
1 parent 19dd063 commit 8681c05
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"path"
"runtime"
"runtime/debug"
"runtime/pprof"
Expand Down Expand Up @@ -86,6 +87,16 @@ func longhornCli() {
meta.GitCommit = GitCommit
meta.BuildDate = BuildDate

logrus.SetReportCaller(true)
logrus.SetFormatter(&logrus.TextFormatter{
CallerPrettyfier: func(f *runtime.Frame) (function string, file string) {
fileName := fmt.Sprintf("%s:%d", path.Base(f.File), f.Line)
funcName := path.Base(f.Function)
return funcName, fileName
},
FullTimestamp: true,
})

a.Before = func(c *cli.Context) error {
if c.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel)
Expand Down

0 comments on commit 8681c05

Please sign in to comment.