mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-16 18:21:24 +01:00
Enable Report Caller when log level Debug (#258)
Enabling report caller when log level equals debug Also added a Caller prettyfier to avoid full file path
This commit is contained in:
parent
c1b162c974
commit
24d5f9efac
12
util/log.go
12
util/log.go
@ -4,7 +4,10 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
"io"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -31,6 +34,15 @@ func InitLog(logLevel string, logPath string) error {
|
||||
logFormatter := new(log.TextFormatter)
|
||||
logFormatter.TimestampFormat = time.RFC3339 // or RFC3339
|
||||
logFormatter.FullTimestamp = true
|
||||
logFormatter.CallerPrettyfier = func(frame *runtime.Frame) (function string, file string) {
|
||||
fileName := path.Base(frame.File) + ":" + strconv.Itoa(frame.Line)
|
||||
//return frame.Function, fileName
|
||||
return "", fileName
|
||||
}
|
||||
|
||||
if level == log.DebugLevel {
|
||||
log.SetReportCaller(true)
|
||||
}
|
||||
|
||||
log.SetFormatter(logFormatter)
|
||||
log.SetLevel(level)
|
||||
|
Loading…
Reference in New Issue
Block a user