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 d78c035 commit a7d1416
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package main

import (
"fmt"
"os"
"path"
"runtime"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
Expand All @@ -25,6 +28,16 @@ func main() {
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 a7d1416

Please sign in to comment.