commit 754306c3151e3580e9674a7f5ea0b5585c6accc3
Author: Wim <wim@42.be>
Date: Wed Feb 21 00:20:25 2018 +0000
diff --git a/bridge/api/api.go b/bridge/api/api.go
index 6055cd5..cbea9ee 100644
--- a/bridge/api/api.go
+++ b/bridge/api/api.go
@@ -307 +307 @@ var flog *log.Entry
var protocol = "api"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *Api {
diff --git a/bridge/bridge.go b/bridge/bridge.go
index 0a2bfed..87db37e 100644
--- a/bridge/bridge.go
+++ b/bridge/bridge.go
@@ -366 +3612 @@ type Bridge struct {
Joined map[string]bool
}
+var flog *log.Entry
+
+func init() {
+ flog = log.WithFields(log.Fields{"prefix": "bridge"})
+}
+
func New(cfg *config.Config, bridge *config.Bridge, c chan config.Message) *Bridge {
b := new(Bridge)
b.Channels = make(map[string]config.ChannelInfo)
@@ -1007 +1067 @@ func (b *Bridge) JoinChannels() error {
func (b *Bridge) joinChannels(channels map[string]config.ChannelInfo, exists map[string]bool) error {
for ID, channel := range channels {
if !exists[ID] {
- log.Infof("%s: joining %s (ID: %s)", b.Account, channel.Name, ID)
+ flog.Infof("%s: joining %s (ID: %s)", b.Account, channel.Name, ID)
err := b.JoinChannel(channel)
if err != nil {
return err
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index 70e11e0..4ca6814 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -48 +48 @@ import (
"bytes"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
- log "github.com/sirupsen/logrus"
"github.com/bwmarrin/discordgo"
+ log "github.com/sirupsen/logrus"
"regexp"
"strings"
"sync"
@@ -297 +297 @@ var flog *log.Entry
var protocol = "discord"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *bdiscord {
diff --git a/bridge/gitter/gitter.go b/bridge/gitter/gitter.go
index 9f988f5..f11af6a 100644
--- a/bridge/gitter/gitter.go
+++ b/bridge/gitter/gitter.go
@@ -217 +217 @@ var flog *log.Entry
var protocol = "gitter"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *Bgitter {
diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go
index d7b45b7..958eb6c 100644
--- a/bridge/irc/irc.go
+++ b/bridge/irc/irc.go
@@ -611 +611 @@ import (
"fmt"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/bridge/helper"
- log "github.com/sirupsen/logrus"
"github.com/lrstanley/girc"
"github.com/paulrosania/go-charset/charset"
_ "github.com/paulrosania/go-charset/data"
"github.com/saintfish/chardet"
+ log "github.com/sirupsen/logrus"
"io"
"io/ioutil"
"net"
@@ -377 +377 @@ var flog *log.Entry
var protocol = "irc"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *Birc {
diff --git a/bridge/matrix/matrix.go b/bridge/matrix/matrix.go
index d0b435e..5661635 100644
--- a/bridge/matrix/matrix.go
+++ b/bridge/matrix/matrix.go
@@ -257 +257 @@ var flog *log.Entry
var protocol = "matrix"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *Bmatrix {
diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go
index 2b93b9b..bd1292b 100644
--- a/bridge/mattermost/mattermost.go
+++ b/bridge/mattermost/mattermost.go
@@ -427 +427 @@ var flog *log.Entry
var protocol = "mattermost"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *Bmattermost {
diff --git a/bridge/rocketchat/rocketchat.go b/bridge/rocketchat/rocketchat.go
index 893cea7..dec02e5 100644
--- a/bridge/rocketchat/rocketchat.go
+++ b/bridge/rocketchat/rocketchat.go
@@ -227 +227 @@ var flog *log.Entry
var protocol = "rocketchat"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *Brocketchat {
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go
index fa49da9..8088644 100644
--- a/bridge/slack/slack.go
+++ b/bridge/slack/slack.go
@@ -407 +407 @@ var flog *log.Entry
var protocol = "slack"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *Bslack {
diff --git a/bridge/sshchat/sshchat.go b/bridge/sshchat/sshchat.go
index 4b91df0..cce4da5 100644
--- a/bridge/sshchat/sshchat.go
+++ b/bridge/sshchat/sshchat.go
@@ -207 +207 @@ var flog *log.Entry
var protocol = "sshchat"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *Bsshchat {
diff --git a/bridge/steam/steam.go b/bridge/steam/steam.go
index 2ce6e0b..b630c42 100644
--- a/bridge/steam/steam.go
+++ b/bridge/steam/steam.go
@@ -257 +257 @@ var flog *log.Entry
var protocol = "steam"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *Bsteam {
diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go
index 6385357..e411690 100644
--- a/bridge/telegram/telegram.go
+++ b/bridge/telegram/telegram.go
@@ -217 +217 @@ var flog *log.Entry
var protocol = "telegram"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *Btelegram {
diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go
index c2f63e7..45daee1 100644
--- a/bridge/xmpp/xmpp.go
+++ b/bridge/xmpp/xmpp.go
@@ -227 +227 @@ var flog *log.Entry
var protocol = "xmpp"
func init() {
- flog = log.WithFields(log.Fields{"module": protocol})
+ flog = log.WithFields(log.Fields{"prefix": protocol})
}
func New(cfg *config.BridgeConfig) *Bxmpp {
diff --git a/gateway/gateway.go b/gateway/gateway.go
index 27f6ffc..e2db20e 100644
--- a/gateway/gateway.go
+++ b/gateway/gateway.go
@@ -346 +3412 @@ type BrMsgID struct {
ChannelID string
}
+var flog *log.Entry
+
+func init() {
+ flog = log.WithFields(log.Fields{"prefix": "gateway"})
+}
+
func New(cfg config.Gateway, r *Router) *Gateway {
gw := &Gateway{Channels: make(map[string]*config.ChannelInfo), Message: r.Message,
Router: r, Bridges: make(map[string]*bridge.Bridge), Config: r.Config}
@@ -7810 +8410 @@ func (gw *Gateway) reconnectBridge(br *bridge.Bridge) {
br.Disconnect()
time.Sleep(time.Second * 5)
RECONNECT:
- log.Infof("Reconnecting %s", br.Account)
+ flog.Infof("Reconnecting %s", br.Account)
err := br.Connect()
if err != nil {
- log.Errorf("Reconnection failed: %s. Trying again in 60 seconds", err)
+ flog.Errorf("Reconnection failed: %s. Trying again in 60 seconds", err)
time.Sleep(time.Second * 60)
goto RECONNECT
}
@@ -1457 +1517 @@ func (gw *Gateway) getDestChannel(msg *config.Message, dest bridge.Bridge) []con
continue
}
- // do samechannelgateway logic
+ // do samechannelgateway flogic
if channel.SameChannel[msg.Gateway] {
if msg.Channel == channel.Name && msg.Account != dest.Account {
channels = append(channels, *channel)
@@ -1967 +2027 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
// broadcast to every out channel (irc QUIT)
if msg.Channel == "" && msg.Event != config.EVENT_JOIN_LEAVE {
- log.Debug("empty channel")
+ flog.Debug("empty channel")
return brMsgIDs
}
originchannel := msg.Channel
@@ -2147 +2207 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
continue
}
}
- log.Debugf("Sending %#v from %s (%s) to %s (%s)", msg, msg.Account, originchannel, dest.Account, channel.Name)
+ flog.Debugf("Sending %#v from %s (%s) to %s (%s)", msg, msg.Account, originchannel, dest.Account, channel.Name)
msg.Channel = channel.Name
msg.Avatar = gw.modifyAvatar(origmsg, dest)
msg.Username = gw.modifyUsername(origmsg, dest)
@@ -25812 +26412 @@ func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
len(msg.Extra[config.EVENT_FILE_FAILURE_SIZE]) > 0) {
return false
}
- log.Debugf("ignoring empty message %#v from %s", msg, msg.Account)
+ flog.Debugf("ignoring empty message %#v from %s", msg, msg.Account)
return true
}
for _, entry := range strings.Fields(gw.Bridges[msg.Account].Config.IgnoreNicks) {
if msg.Username == entry {
- log.Debugf("ignoring %s from %s", msg.Username, msg.Account)
+ flog.Debugf("ignoring %s from %s", msg.Username, msg.Account)
return true
}
}
@@ -27211 +27811 @@ func (gw *Gateway) ignoreMessage(msg *config.Message) bool {
if entry != "" {
re, err := regexp.Compile(entry)
if err != nil {
- log.Errorf("incorrect regexp %s for %s", entry, msg.Account)
+ flog.Errorf("incorrect regexp %s for %s", entry, msg.Account)
continue
}
if re.MatchString(msg.Text) {
- log.Debugf("matching %s. ignoring %s from %s", entry, msg.Text, msg.Account)
+ flog.Debugf("matching %s. ignoring %s from %s", entry, msg.Text, msg.Account)
return true
}
}
@@ -3037 +3097 @@ func (gw *Gateway) modifyUsername(msg config.Message, dest *bridge.Bridge) strin
// TODO move compile to bridge init somewhere
re, err := regexp.Compile(search)
if err != nil {
- log.Errorf("regexp in %s failed: %s", msg.Account, err)
+ flog.Errorf("regexp in %s failed: %s", msg.Account, err)
break
}
msg.Username = re.ReplaceAllString(msg.Username, replace)
@@ -3517 +3577 @@ func (gw *Gateway) modifyMessage(msg *config.Message) {
// TODO move compile to bridge init somewhere
re, err := regexp.Compile(search)
if err != nil {
- log.Errorf("regexp in %s failed: %s", msg.Account, err)
+ flog.Errorf("regexp in %s failed: %s", msg.Account, err)
break
}
msg.Text = re.ReplaceAllString(msg.Text, replace)
@@ -38310 +38910 @@ func (gw *Gateway) handleFiles(msg *config.Message) {
req.Header.Set("Content-Type", "binary/octet-stream")
_, err := client.Do(req)
if err != nil {
- log.Errorf("mediaserver upload failed: %#v", err)
+ flog.Errorf("mediaserver upload failed: %#v", err)
continue
}
- log.Debugf("mediaserver download URL = %s", durl)
+ flog.Debugf("mediaserver download URL = %s", durl)
// we uploaded the file successfully. Add the SHA
extra.SHA = sha1sum
msg.Extra["file"][i] = extra
diff --git a/gateway/router.go b/gateway/router.go
index e1944d4..7c3d858 100644
--- a/gateway/router.go
+++ b/gateway/router.go
@@ -57 +57 @@ import (
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
"github.com/42wim/matterbridge/gateway/samechannel"
- log "github.com/sirupsen/logrus"
+ //log "github.com/sirupsen/logrus"
// "github.com/davecgh/go-spew/spew"
"time"
)
@@ -4213 +4213 @@ func NewRouter(cfg *config.Config) (*Router, error) {
func (r *Router) Start() error {
m := make(map[string]*bridge.Bridge)
for _, gw := range r.Gateways {
- log.Infof("Parsing gateway %s", gw.Name)
+ flog.Infof("Parsing gateway %s", gw.Name)
for _, br := range gw.Bridges {
m[br.Account] = br
}
}
for _, br := range m {
- log.Infof("Starting bridge: %s ", br.Account)
+ flog.Infof("Starting bridge: %s ", br.Account)
err := br.Connect()
if err != nil {
return fmt.Errorf("Bridge %s failed to start: %v", br.Account, err)
diff --git a/matterbridge.go b/matterbridge.go
index 0691a1f..5e1e3f4 100644
--- a/matterbridge.go
+++ b/matterbridge.go
@@ -187 +188 @@ var (
)
func main() {
- log.SetFormatter(&prefixed.TextFormatter{FullTimestamp: true})
+ log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 10, 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")
flagVersion := flag.Bool("version", false, "show version")
@@ -3324 +3424 @@ func main() {
return
}
if *flagDebug || os.Getenv("DEBUG") == "1" {
- log.SetFormatter(&prefixed.TextFormatter{FullTimestamp: false})
- log.Info("Enabling debug")
+ log.SetFormatter(&prefixed.TextFormatter{PrefixPadding: 10, DisableColors: true, FullTimestamp: false})
+ flog.Info("Enabling debug")
log.SetLevel(log.DebugLevel)
}
- log.Printf("Running version %s %s", version, githash)
+ flog.Printf("Running version %s %s", version, githash)
if strings.Contains(version, "-dev") {
- log.Println("WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.")
+ flog.Println("WARNING: THIS IS A DEVELOPMENT VERSION. Things may break.")
}
cfg := config.NewConfig(*flagConfig)
cfg.General.Debug = *flagDebug
r, err := gateway.NewRouter(cfg)
if err != nil {
- log.Fatalf("Starting gateway failed: %s", err)
+ flog.Fatalf("Starting gateway failed: %s", err)
}
err = r.Start()
if err != nil {
- log.Fatalf("Starting gateway failed: %s", err)
+ flog.Fatalf("Starting gateway failed: %s", err)
}
- log.Printf("Gateway(s) started succesfully. Now relaying messages")
+ flog.Printf("Gateway(s) started succesfully. Now relaying messages")
select {}
}