Thumbnail

rani/matterbridge.git

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

commit f9a01bab95a2201c201fac5d5c549ca18eab8d96 Author: Wim <wim@42.be> Date: Wed Feb 21 01:11:41 2018 +0000 Make matterclient work with prefixed log diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index bd1292b..f620649 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -3646 +3649 @@ func (b *Bmattermost) apiLogin() error {     b.mc = matterclient.New(b.Config.Login, password,   b.Config.Team, b.Config.Server) + if b.General.Debug { + b.mc.SetLogLevel("debug") + }   b.mc.SkipTLSVerify = b.Config.SkipTLSVerify   b.mc.NoTLS = b.Config.NoTLS   flog.Infof("Connecting %s (team: %s) on %s", b.Config.Login, b.Config.Team, b.Config.Server) diff --git a/matterbridge.go b/matterbridge.go index 5e1e3f4..aa92bf0 100644 --- a/matterbridge.go +++ b/matterbridge.go @@ -187 +187 @@ var (  )    func main() { - log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 10, DisableColors: true, FullTimestamp: true}) + log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 13, DisableColors: true, FullTimestamp: true})   flog := log.WithFields(log.Fields{"prefix": "main"})   flagConfig := flag.String("conf", "matterbridge.toml", "config file")   flagDebug := flag.Bool("debug", false, "enable debug") @@ -347 +347 @@ func main() {   return   }   if *flagDebug || os.Getenv("DEBUG") == "1" { - log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 10, DisableColors: true, FullTimestamp: false}) + log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 13, DisableColors: true, FullTimestamp: false})   flog.Info("Enabling debug")   log.SetLevel(log.DebugLevel)   } diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go index 9e44705..27e9616 100644 --- a/matterclient/matterclient.go +++ b/matterclient/matterclient.go @@ -146 +147 @@ import (   "time"     log "github.com/sirupsen/logrus" + prefixed "github.com/x-cray/logrus-prefixed-formatter"     "github.com/gorilla/websocket"   "github.com/hashicorp/golang-lru" @@ -7312 +7416 @@ type MMClient struct {  func New(login, pass, team, server string) *MMClient {   cred := &Credentials{Login: login, Pass: pass, Team: team, Server: server}   mmclient := &MMClient{Credentials: cred, MessageChan: make(chan *Message, 100), Users: make(map[string]*model.User)} - mmclient.log = log.WithFields(log.Fields{"module": "matterclient"}) - log.SetFormatter(&log.TextFormatter{FullTimestamp: true}) + log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 13, DisableColors: true}) + mmclient.log = log.WithFields(log.Fields{"prefix": "matterclient"})   mmclient.lruCache, _ = lru.New(500)   return mmclient  }   +func (m *MMClient) SetDebugLog() { + log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 13, DisableColors: true, FullTimestamp: false}) +} +  func (m *MMClient) SetLogLevel(level string) {   l, err := log.ParseLevel(level)   if err != nil {