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 <jack.lin@suse.com>
  • Loading branch information
ChanYiLin authored and David Ko committed Oct 20, 2023
1 parent c93aea9 commit 5b8bbc3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"fmt"
"os"
"path"
"runtime"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
Expand All @@ -20,7 +22,15 @@ func onUsageError(c *cli.Context, err error, isSubcommand bool) error {
}

func main() {
logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})
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 := cli.NewApp()
a.Usage = "Longhorn Manager"
Expand Down

0 comments on commit 5b8bbc3

Please sign in to comment.