mirror of
https://github.com/mattermost/focalboard.git
synced 2025-01-05 14:50:29 +02:00
Merge branch 'main' of github.com:mattermost/focalboard
This commit is contained in:
commit
70bdf41f28
@ -8,6 +8,8 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mattermost/logr/v2"
|
"github.com/mattermost/logr/v2"
|
||||||
@ -18,6 +20,18 @@ const (
|
|||||||
ShutdownTimeout = time.Second * 15
|
ShutdownTimeout = time.Second * 15
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
mlogPkg string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// Calc current package name
|
||||||
|
pcs := make([]uintptr, 2)
|
||||||
|
_ = runtime.Callers(0, pcs)
|
||||||
|
tmp := runtime.FuncForPC(pcs[1]).Name()
|
||||||
|
mlogPkg = GetPackageName(tmp)
|
||||||
|
}
|
||||||
|
|
||||||
// Type and function aliases from Logr to limit the spread of dependencies throughout Focalboard.
|
// Type and function aliases from Logr to limit the spread of dependencies throughout Focalboard.
|
||||||
type Field = logr.Field
|
type Field = logr.Field
|
||||||
type Level = logr.Level
|
type Level = logr.Level
|
||||||
@ -108,6 +122,8 @@ type Logger struct {
|
|||||||
|
|
||||||
// NewLogger creates a new Logger instance which can be configured via `(*Logger).Configure`.
|
// NewLogger creates a new Logger instance which can be configured via `(*Logger).Configure`.
|
||||||
func NewLogger(options ...Option) *Logger {
|
func NewLogger(options ...Option) *Logger {
|
||||||
|
options = append(options, logr.StackFilter(GetPackageName(mlogPkg)))
|
||||||
|
|
||||||
lgr, _ := logr.New(options...)
|
lgr, _ := logr.New(options...)
|
||||||
log := lgr.NewLogger()
|
log := lgr.NewLogger()
|
||||||
|
|
||||||
@ -248,3 +264,18 @@ func (l *Logger) Shutdown() error {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
return l.log.Logr().ShutdownWithTimeout(ctx)
|
return l.log.Logr().ShutdownWithTimeout(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPackageName reduces a fully qualified function name to the package name
|
||||||
|
// By sirupsen: https://github.com/sirupsen/logrus/blob/master/entry.go
|
||||||
|
func GetPackageName(f string) string {
|
||||||
|
for {
|
||||||
|
lastPeriod := strings.LastIndex(f, ".")
|
||||||
|
lastSlash := strings.LastIndex(f, "/")
|
||||||
|
if lastPeriod > lastSlash {
|
||||||
|
f = f[:lastPeriod]
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user