mirror of
https://github.com/netbirdio/netbird.git
synced 2025-04-30 14:25:06 +02: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"
|
log "github.com/sirupsen/logrus"
|
||||||
"gopkg.in/natefinch/lumberjack.v2"
|
"gopkg.in/natefinch/lumberjack.v2"
|
||||||
"io"
|
"io"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,6 +34,15 @@ func InitLog(logLevel string, logPath string) error {
|
|||||||
logFormatter := new(log.TextFormatter)
|
logFormatter := new(log.TextFormatter)
|
||||||
logFormatter.TimestampFormat = time.RFC3339 // or RFC3339
|
logFormatter.TimestampFormat = time.RFC3339 // or RFC3339
|
||||||
logFormatter.FullTimestamp = true
|
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.SetFormatter(logFormatter)
|
||||||
log.SetLevel(level)
|
log.SetLevel(level)
|
||||||
|
Loading…
Reference in New Issue
Block a user