Files
kubevpn/util/log.go
p_caiwfeng db39003e4f add comment
2021-10-20 15:11:21 +08:00

31 lines
573 B
Go

package util
import (
"fmt"
log "github.com/sirupsen/logrus"
"path/filepath"
)
func SetupLogger(debug bool) {
if debug {
log.SetLevel(log.DebugLevel)
}
log.SetReportCaller(true)
log.SetFormatter(&Format{})
}
type Format struct {
log.Formatter
}
// 2009/01/23 01:23:23 d.go:23: message
// same like log.SetFlags(log.LstdFlags | log.Lshortfile)
func (*Format) Format(e *log.Entry) ([]byte, error) {
return []byte(
fmt.Sprintf("%s %s:%d: %s\n",
e.Time.Format("2006/01/02 15:04:05"),
filepath.Base(e.Caller.File),
e.Caller.Line,
e.Message)), nil
}