diff options
author | Wim <wim@42.be> | 2020-05-24 13:58:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-24 13:58:15 +0200 |
commit | 9440b9e3138805945214aa4d86368bb40da07cc2 (patch) | |
tree | 611fe471c477407c58faea15828bc5d31284883d /matterbridge.go | |
parent | 393f9e998b1b40aa59d3fb8794c3a73da38c3fb7 (diff) | |
download | matterbridge-msglm-9440b9e3138805945214aa4d86368bb40da07cc2.tar.gz matterbridge-msglm-9440b9e3138805945214aa4d86368bb40da07cc2.tar.bz2 matterbridge-msglm-9440b9e3138805945214aa4d86368bb40da07cc2.zip |
Increase debug logging with function,file and linenumber (#1147)
Show the function name,file and linenumber like this
[0000] INFO main: [setupLogger:matterbridge.go:100] Enabling debug logging.
[0000] INFO main: [main:matterbridge.go:46] Running version 1.17.5-dev
Only enable this for debug as this adds some overhead.
Diffstat (limited to 'matterbridge.go')
-rw-r--r-- | matterbridge.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/matterbridge.go b/matterbridge.go index da0df103..24caa5d9 100644 --- a/matterbridge.go +++ b/matterbridge.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "os" + "runtime" "strings" "github.com/42wim/matterbridge/bridge/config" @@ -67,17 +68,31 @@ func setupLogger() *logrus.Logger { Formatter: &prefixed.TextFormatter{ PrefixPadding: 13, DisableColors: true, - FullTimestamp: true, }, Level: logrus.InfoLevel, } if *flagDebug || os.Getenv("DEBUG") == "1" { + logger.SetReportCaller(true) logger.Formatter = &prefixed.TextFormatter{ - PrefixPadding: 13, - DisableColors: true, - FullTimestamp: false, - ForceFormatting: true, + PrefixPadding: 13, + DisableColors: true, + FullTimestamp: false, + + CallerFormatter: func(function, file string) string { + return fmt.Sprintf(" [%s:%s]", function, file) + }, + CallerPrettyfier: func(f *runtime.Frame) (string, string) { + sp := strings.SplitAfter(f.File, "/matterbridge/") + filename := f.File + if len(sp) > 1 { + filename = sp[1] + } + s := strings.Split(f.Function, ".") + funcName := s[len(s)-1] + return funcName, fmt.Sprintf("%s:%d", filename, f.Line) + }, } + logger.Level = logrus.DebugLevel logger.WithFields(logrus.Fields{"prefix": "main"}).Info("Enabling debug logging.") } |