Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit fc53d07e1e9b45f5a71332ff7e2366e29f5eb3ba Author: Wim <wim@42.be> Date: Sun May 24 13:58:15 2020 +0000 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. diff --git a/go.mod b/go.mod index dc1e29d..e29b3cb 100644 --- a/go.mod +++ b/go.mod @@ -267 +267 @@ require (   github.com/matterbridge/go-xmpp v0.0.0-20200418225040-c8a3a57b4050   github.com/matterbridge/gomatrix v0.0.0-20200209224845-c2104d7936a6   github.com/matterbridge/gozulipbot v0.0.0-20190212232658-7aa251978a18 - github.com/matterbridge/logrus-prefixed-formatter v0.0.0-20180806162718-01618749af61 + github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba   github.com/mattermost/mattermost-server v5.5.0+incompatible   github.com/mattn/godown v0.0.0-20200217152941-afc959f6a561   github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect diff --git a/go.sum b/go.sum index 436a03b..c1e79f8 100644 --- a/go.sum +++ b/go.sum @@ -1898 +1898 @@ github.com/matterbridge/gomatrix v0.0.0-20200209224845-c2104d7936a6 h1:Kl65VJv38  github.com/matterbridge/gomatrix v0.0.0-20200209224845-c2104d7936a6/go.mod h1:+jWeaaUtXQbBRdKYWfjW6JDDYiI2XXE+3NnTjW5kg8g=  github.com/matterbridge/gozulipbot v0.0.0-20190212232658-7aa251978a18 h1:fLhwXtWGtfTgZVxHG1lcKjv+re7dRwyyuYFNu69xdho=  github.com/matterbridge/gozulipbot v0.0.0-20190212232658-7aa251978a18/go.mod h1:yAjnZ34DuDyPHMPHHjOsTk/FefW4JJjoMMCGt/8uuQA= -github.com/matterbridge/logrus-prefixed-formatter v0.0.0-20180806162718-01618749af61 h1:R/MgM/eUyRBQx2FiH6JVmXck8PaAuKfe2M1tWIzW7nE= -github.com/matterbridge/logrus-prefixed-formatter v0.0.0-20180806162718-01618749af61/go.mod h1:iXGEotOvwI1R1SjLxRc+BF5rUORTMtE0iMZBT2lxqAU= +github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba h1:XleOY4IjAEIcxAh+IFwT5JT5Ze3RHiYz6m+4ZfZ0rc0= +github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba/go.mod h1:iXGEotOvwI1R1SjLxRc+BF5rUORTMtE0iMZBT2lxqAU=  github.com/mattermost/mattermost-server v5.5.0+incompatible h1:0wcLGgYtd+YImtLDPf2AOfpBHxbU4suATx+6XKw1XbU=  github.com/mattermost/mattermost-server v5.5.0+incompatible/go.mod h1:5L6MjAec+XXQwMIt791Ganu45GKsSiM+I0tLR9wUj8Y=  github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= diff --git a/matterbridge.go b/matterbridge.go index da0df10..24caa5d 100644 --- a/matterbridge.go +++ b/matterbridge.go @@ -46 +47 @@ import (   "flag"   "fmt"   "os" + "runtime"   "strings"     "github.com/42wim/matterbridge/bridge/config" @@ -6717 +6831 @@ 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.")   }