Improve debug messages

This commit is contained in:
Wim 2018-02-28 22:23:29 +01:00
parent 20dbd71306
commit 594d2155e3
12 changed files with 39 additions and 39 deletions

View File

@ -96,7 +96,7 @@ func (b *Bdiscord) JoinChannel(channel config.ChannelInfo) error {
} }
func (b *Bdiscord) Send(msg config.Message) (string, error) { func (b *Bdiscord) Send(msg config.Message) (string, error) {
b.Log.Debugf("Receiving %#v", msg) b.Log.Debugf("=> Receiving %#v", msg)
channelID := b.getChannelID(msg.Channel) channelID := b.getChannelID(msg.Channel)
if channelID == "" { if channelID == "" {
@ -180,8 +180,8 @@ func (b *Bdiscord) messageDelete(s *discordgo.Session, m *discordgo.MessageDelet
if b.UseChannelID { if b.UseChannelID {
rmsg.Channel = "ID:" + m.ChannelID rmsg.Channel = "ID:" + m.ChannelID
} }
b.Log.Debugf("Sending message from %s to gateway", b.Account) b.Log.Debugf("<= Sending message from %s to gateway", b.Account)
b.Log.Debugf("Message is %#v", rmsg) b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg b.Remote <- rmsg
} }
@ -219,7 +219,7 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
rmsg := config.Message{Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg", UserID: m.Author.ID, ID: m.ID} rmsg := config.Message{Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg", UserID: m.Author.ID, ID: m.ID}
if m.Content != "" { if m.Content != "" {
b.Log.Debugf("Receiving message %#v", m.Message) b.Log.Debugf("== Receiving event %#v", m.Message)
m.Message.Content = b.stripCustomoji(m.Message.Content) m.Message.Content = b.stripCustomoji(m.Message.Content)
m.Message.Content = b.replaceChannelMentions(m.Message.Content) m.Message.Content = b.replaceChannelMentions(m.Message.Content)
rmsg.Text, err = m.ContentWithMoreMentionsReplaced(b.c) rmsg.Text, err = m.ContentWithMoreMentionsReplaced(b.c)
@ -261,8 +261,8 @@ func (b *Bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat
rmsg.Event = config.EVENT_USER_ACTION rmsg.Event = config.EVENT_USER_ACTION
} }
b.Log.Debugf("Sending message from %s on %s to gateway", m.Author.Username, b.Account) b.Log.Debugf("<= Sending message from %s on %s to gateway", m.Author.Username, b.Account)
b.Log.Debugf("Message is %#v", rmsg) b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg b.Remote <- rmsg
} }

View File

@ -71,7 +71,7 @@ func (b *Bgitter) JoinChannel(channel config.ChannelInfo) error {
case *gitter.MessageReceived: case *gitter.MessageReceived:
// ignore message sent from ourselves // ignore message sent from ourselves
if ev.Message.From.ID != b.User.ID { if ev.Message.From.ID != b.User.ID {
b.Log.Debugf("Sending message from %s on %s to gateway", ev.Message.From.Username, b.Account) b.Log.Debugf("<= Sending message from %s on %s to gateway", ev.Message.From.Username, b.Account)
rmsg := config.Message{Username: ev.Message.From.Username, Text: ev.Message.Text, Channel: room, rmsg := config.Message{Username: ev.Message.From.Username, Text: ev.Message.Text, Channel: room,
Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username), UserID: ev.Message.From.ID, Account: b.Account, Avatar: b.getAvatar(ev.Message.From.Username), UserID: ev.Message.From.ID,
ID: ev.Message.ID} ID: ev.Message.ID}
@ -79,7 +79,7 @@ func (b *Bgitter) JoinChannel(channel config.ChannelInfo) error {
rmsg.Event = config.EVENT_USER_ACTION rmsg.Event = config.EVENT_USER_ACTION
rmsg.Text = strings.Replace(rmsg.Text, "@"+ev.Message.From.Username+" ", "", -1) rmsg.Text = strings.Replace(rmsg.Text, "@"+ev.Message.From.Username+" ", "", -1)
} }
b.Log.Debugf("Message is %#v", rmsg) b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg b.Remote <- rmsg
} }
case *gitter.GitterConnectionClosed: case *gitter.GitterConnectionClosed:
@ -91,7 +91,7 @@ func (b *Bgitter) JoinChannel(channel config.ChannelInfo) error {
} }
func (b *Bgitter) Send(msg config.Message) (string, error) { func (b *Bgitter) Send(msg config.Message) (string, error) {
b.Log.Debugf("Receiving %#v", msg) b.Log.Debugf("=> Receiving %#v", msg)
roomID := b.getRoomID(msg.Channel) roomID := b.getRoomID(msg.Channel)
if roomID == "" { if roomID == "" {
b.Log.Errorf("Could not find roomID for %v", msg.Channel) b.Log.Errorf("Could not find roomID for %v", msg.Channel)

View File

@ -156,7 +156,7 @@ func (b *Birc) Send(msg config.Message) (string, error) {
return "", nil return "", nil
} }
b.Log.Debugf("Receiving %#v", msg) b.Log.Debugf("=> Receiving %#v", msg)
// Execute a command // Execute a command
if strings.HasPrefix(msg.Text, "!") { if strings.HasPrefix(msg.Text, "!") {
@ -289,9 +289,9 @@ func (b *Birc) handleJoinPart(client *girc.Client, event girc.Event) {
} }
} }
if event.Source.Name != b.Nick { if event.Source.Name != b.Nick {
b.Log.Debugf("Sending JOIN_LEAVE event from %s to gateway", b.Account) b.Log.Debugf("<= Sending JOIN_LEAVE event from %s to gateway", b.Account)
msg := config.Message{Username: "system", Text: event.Source.Name + " " + strings.ToLower(event.Command) + "s", Channel: channel, Account: b.Account, Event: config.EVENT_JOIN_LEAVE} msg := config.Message{Username: "system", Text: event.Source.Name + " " + strings.ToLower(event.Command) + "s", Channel: channel, Account: b.Account, Event: config.EVENT_JOIN_LEAVE}
b.Log.Debugf("Message is %#v", msg) b.Log.Debugf("<= Message is %#v", msg)
b.Remote <- msg b.Remote <- msg
return return
} }
@ -352,7 +352,7 @@ func (b *Birc) handlePrivMsg(client *girc.Client, event girc.Event) {
return return
} }
rmsg := config.Message{Username: event.Source.Name, Channel: strings.ToLower(event.Params[0]), Account: b.Account, UserID: event.Source.Ident + "@" + event.Source.Host} rmsg := config.Message{Username: event.Source.Name, Channel: strings.ToLower(event.Params[0]), Account: b.Account, UserID: event.Source.Ident + "@" + event.Source.Host}
b.Log.Debugf("Receiving PRIVMSG: %s %s %#v", event.Source.Name, event.Trailing, event) b.Log.Debugf("== Receiving PRIVMSG: %s %s %#v", event.Source.Name, event.Trailing, event)
// set action event // set action event
if event.IsAction() { if event.IsAction() {
@ -393,7 +393,7 @@ func (b *Birc) handlePrivMsg(client *girc.Client, event girc.Event) {
output, _ := ioutil.ReadAll(r) output, _ := ioutil.ReadAll(r)
rmsg.Text = string(output) rmsg.Text = string(output)
b.Log.Debugf("Sending message from %s on %s to gateway", event.Params[0], b.Account) b.Log.Debugf("<= Sending message from %s on %s to gateway", event.Params[0], b.Account)
b.Remote <- rmsg b.Remote <- rmsg
} }

View File

@ -65,7 +65,7 @@ func (b *Bmatrix) JoinChannel(channel config.ChannelInfo) error {
} }
func (b *Bmatrix) Send(msg config.Message) (string, error) { func (b *Bmatrix) Send(msg config.Message) (string, error) {
b.Log.Debugf("Receiving %#v", msg) b.Log.Debugf("=> Receiving %#v", msg)
channel := b.getRoomID(msg.Channel) channel := b.getRoomID(msg.Channel)
b.Log.Debugf("Channel %s maps to channel id %s", msg.Channel, channel) b.Log.Debugf("Channel %s maps to channel id %s", msg.Channel, channel)
@ -140,7 +140,7 @@ func (b *Bmatrix) handlematrix() error {
} }
func (b *Bmatrix) handleEvent(ev *matrix.Event) { func (b *Bmatrix) handleEvent(ev *matrix.Event) {
b.Log.Debugf("Received: %#v", ev) b.Log.Debugf("== Receiving event: %#v", ev)
if ev.Sender != b.UserID { if ev.Sender != b.UserID {
b.RLock() b.RLock()
channel, ok := b.RoomMap[ev.RoomID] channel, ok := b.RoomMap[ev.RoomID]
@ -189,7 +189,7 @@ func (b *Bmatrix) handleEvent(ev *matrix.Event) {
} }
} }
b.Log.Debugf("Sending message from %s on %s to gateway", ev.Sender, b.Account) b.Log.Debugf("<= Sending message from %s on %s to gateway", ev.Sender, b.Account)
b.Remote <- rmsg b.Remote <- rmsg
} }
} }

View File

@ -115,7 +115,7 @@ func (b *Bmattermost) JoinChannel(channel config.ChannelInfo) error {
} }
func (b *Bmattermost) Send(msg config.Message) (string, error) { func (b *Bmattermost) Send(msg config.Message) (string, error) {
b.Log.Debugf("Receiving %#v", msg) b.Log.Debugf("=> Receiving %#v", msg)
// Make a action /me of the message // Make a action /me of the message
if msg.Event == config.EVENT_USER_ACTION { if msg.Event == config.EVENT_USER_ACTION {
@ -185,8 +185,8 @@ func (b *Bmattermost) handleMatter() {
if ok { if ok {
message.Event = config.EVENT_USER_ACTION message.Event = config.EVENT_USER_ACTION
} }
b.Log.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account) b.Log.Debugf("<= Sending message from %s on %s to gateway", message.Username, b.Account)
b.Log.Debugf("Message is %#v", message) b.Log.Debugf("<= Message is %#v", message)
b.Remote <- *message b.Remote <- *message
} }
} }
@ -205,7 +205,7 @@ func (b *Bmattermost) handleMatterClient(messages chan *config.Message) {
b.handleDownloadAvatar(message.UserID, message.Channel) b.handleDownloadAvatar(message.UserID, message.Channel)
} }
b.Log.Debugf("Receiving from matterclient %#v", message) b.Log.Debugf("== Receiving event %#v", message)
rmsg := &config.Message{Username: message.Username, UserID: message.UserID, Channel: message.Channel, Text: message.Text, ID: message.Post.Id, Extra: make(map[string][]interface{})} rmsg := &config.Message{Username: message.Username, UserID: message.UserID, Channel: message.Channel, Text: message.Text, ID: message.Post.Id, Extra: make(map[string][]interface{})}

View File

@ -50,7 +50,7 @@ func (b *Brocketchat) Send(msg config.Message) (string, error) {
if msg.Event == config.EVENT_MSG_DELETE { if msg.Event == config.EVENT_MSG_DELETE {
return "", nil return "", nil
} }
b.Log.Debugf("Receiving %#v", msg) b.Log.Debugf("=> Receiving %#v", msg)
if msg.Extra != nil { if msg.Extra != nil {
for _, rmsg := range helper.HandleExtra(&msg, b.General) { for _, rmsg := range helper.HandleExtra(&msg, b.General) {
matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL, Channel: rmsg.Channel, UserName: rmsg.Username, matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL, Channel: rmsg.Channel, UserName: rmsg.Username,
@ -88,7 +88,7 @@ func (b *Brocketchat) handleRocketHook() {
if message.UserName == b.Config.Nick { if message.UserName == b.Config.Nick {
continue continue
} }
b.Log.Debugf("Sending message from %s on %s to gateway", message.UserName, b.Account) b.Log.Debugf("<= Sending message from %s on %s to gateway", message.UserName, b.Account)
b.Remote <- config.Message{Text: message.Text, Username: message.UserName, Channel: message.ChannelName, Account: b.Account, UserID: message.UserID} b.Remote <- config.Message{Text: message.Text, Username: message.UserName, Channel: message.ChannelName, Account: b.Account, UserID: message.UserID}
} }
} }

View File

@ -108,7 +108,7 @@ func (b *Bslack) JoinChannel(channel config.ChannelInfo) error {
} }
func (b *Bslack) Send(msg config.Message) (string, error) { func (b *Bslack) Send(msg config.Message) (string, error) {
b.Log.Debugf("Receiving %#v", msg) b.Log.Debugf("=> Receiving %#v", msg)
// Make a action /me of the message // Make a action /me of the message
if msg.Event == config.EVENT_USER_ACTION { if msg.Event == config.EVENT_USER_ACTION {
@ -190,7 +190,6 @@ func (b *Bslack) Send(msg config.Message) (string, error) {
} }
// Post normal message // Post normal message
b.Log.Debugf("NP IS %#v", np)
_, id, err := b.sc.PostMessage(schannel.ID, msg.Text, np) _, id, err := b.sc.PostMessage(schannel.ID, msg.Text, np)
if err != nil { if err != nil {
return "", err return "", err
@ -246,7 +245,7 @@ func (b *Bslack) handleSlack() {
time.Sleep(time.Second) time.Sleep(time.Second)
b.Log.Debug("Start listening for Slack messages") b.Log.Debug("Start listening for Slack messages")
for message := range messages { for message := range messages {
b.Log.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account) b.Log.Debugf("<= Sending message from %s on %s to gateway", message.Username, b.Account)
// cleanup the message // cleanup the message
message.Text = b.replaceURL(message.Text) message.Text = b.replaceURL(message.Text)
@ -258,7 +257,7 @@ func (b *Bslack) handleSlack() {
// Add the avatar // Add the avatar
message.Avatar = b.getAvatar(message.Username) message.Avatar = b.getAvatar(message.Username)
b.Log.Debugf("Message is %#v", message) b.Log.Debugf("<= Message is %#v", message)
b.Remote <- *message b.Remote <- *message
} }
} }
@ -266,7 +265,7 @@ func (b *Bslack) handleSlack() {
func (b *Bslack) handleSlackClient(messages chan *config.Message) { func (b *Bslack) handleSlackClient(messages chan *config.Message) {
for msg := range b.rtm.IncomingEvents { for msg := range b.rtm.IncomingEvents {
if msg.Type != "user_typing" && msg.Type != "latency_report" { if msg.Type != "user_typing" && msg.Type != "latency_report" {
b.Log.Debugf("Receiving from slackclient %#v", msg.Data) b.Log.Debugf("== Receiving event %#v", msg.Data)
} }
switch ev := msg.Data.(type) { switch ev := msg.Data.(type) {
case *slack.MessageEvent: case *slack.MessageEvent:

View File

@ -55,7 +55,7 @@ func (b *Bsshchat) Send(msg config.Message) (string, error) {
if msg.Event == config.EVENT_MSG_DELETE { if msg.Event == config.EVENT_MSG_DELETE {
return "", nil return "", nil
} }
b.Log.Debugf("Receiving %#v", msg) b.Log.Debugf("=> Receiving %#v", msg)
if msg.Extra != nil { if msg.Extra != nil {
for _, rmsg := range helper.HandleExtra(&msg, b.General) { for _, rmsg := range helper.HandleExtra(&msg, b.General) {
b.w.Write([]byte(rmsg.Username + rmsg.Text + "\r\n")) b.w.Write([]byte(rmsg.Username + rmsg.Text + "\r\n"))
@ -124,7 +124,7 @@ func (b *Bsshchat) handleSshChat() error {
continue continue
} }
if !wait { if !wait {
b.Log.Debugf("message %#v", res) b.Log.Debugf("<= Message %#v", res)
rmsg := config.Message{Username: res[0], Text: strings.Join(res[1:], ":"), Channel: "sshchat", Account: b.Account, UserID: "nick"} rmsg := config.Message{Username: res[0], Text: strings.Join(res[1:], ":"), Channel: "sshchat", Account: b.Account, UserID: "nick"}
b.Remote <- rmsg b.Remote <- rmsg
} }

View File

@ -92,7 +92,7 @@ func (b *Bsteam) handleEvents() {
switch e := event.(type) { switch e := event.(type) {
case *steam.ChatMsgEvent: case *steam.ChatMsgEvent:
b.Log.Debugf("Receiving ChatMsgEvent: %#v", e) b.Log.Debugf("Receiving ChatMsgEvent: %#v", e)
b.Log.Debugf("Sending message from %s on %s to gateway", b.getNick(e.ChatterId), b.Account) b.Log.Debugf("<= Sending message from %s on %s to gateway", b.getNick(e.ChatterId), b.Account)
var channel int64 var channel int64
if e.ChatRoomId == 0 { if e.ChatRoomId == 0 {
channel = int64(e.ChatterId) channel = int64(e.ChatterId)

View File

@ -50,7 +50,7 @@ func (b *Btelegram) JoinChannel(channel config.ChannelInfo) error {
} }
func (b *Btelegram) Send(msg config.Message) (string, error) { func (b *Btelegram) Send(msg config.Message) (string, error) {
b.Log.Debugf("Receiving %#v", msg) b.Log.Debugf("=> Receiving %#v", msg)
// get the chatid // get the chatid
chatid, err := strconv.ParseInt(msg.Channel, 10, 64) chatid, err := strconv.ParseInt(msg.Channel, 10, 64)
@ -119,7 +119,7 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) { func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
for update := range updates { for update := range updates {
b.Log.Debugf("Receiving from telegram: %#v", update.Message) b.Log.Debugf("== Receiving event: %#v", update.Message)
if update.Message == nil && update.ChannelPost == nil { if update.Message == nil && update.ChannelPost == nil {
b.Log.Error("Getting nil messages, this shouldn't happen.") b.Log.Error("Getting nil messages, this shouldn't happen.")
@ -226,8 +226,8 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
if rmsg.Text != "" || len(rmsg.Extra) > 0 { if rmsg.Text != "" || len(rmsg.Extra) > 0 {
rmsg.Avatar = helper.GetAvatar(b.avatarMap, strconv.Itoa(message.From.ID), b.General) rmsg.Avatar = helper.GetAvatar(b.avatarMap, strconv.Itoa(message.From.ID), b.General)
b.Log.Debugf("Sending message from %s on %s to gateway", rmsg.Username, b.Account) b.Log.Debugf("<= Sending message from %s on %s to gateway", rmsg.Username, b.Account)
b.Log.Debugf("Message is %#v", rmsg) b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg b.Remote <- rmsg
} }
} }

View File

@ -72,7 +72,7 @@ func (b *Bxmpp) Send(msg config.Message) (string, error) {
if msg.Event == config.EVENT_MSG_DELETE { if msg.Event == config.EVENT_MSG_DELETE {
return "", nil return "", nil
} }
b.Log.Debugf("Receiving %#v", msg) b.Log.Debugf("=> Receiving %#v", msg)
// Upload a file (in xmpp case send the upload URL because xmpp has no native upload support) // Upload a file (in xmpp case send the upload URL because xmpp has no native upload support)
if msg.Extra != nil { if msg.Extra != nil {
@ -161,8 +161,8 @@ func (b *Bxmpp) handleXMPP() error {
if ok { if ok {
rmsg.Event = config.EVENT_USER_ACTION rmsg.Event = config.EVENT_USER_ACTION
} }
b.Log.Debugf("Sending message from %s on %s to gateway", rmsg.Username, b.Account) b.Log.Debugf("<= Sending message from %s on %s to gateway", rmsg.Username, b.Account)
b.Log.Debugf("Message is %#v", rmsg) b.Log.Debugf("<= Message is %#v", rmsg)
b.Remote <- rmsg b.Remote <- rmsg
} }
case xmpp.Presence: case xmpp.Presence:

View File

@ -256,7 +256,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
continue continue
} }
} }
flog.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.Channel = channel.Name
msg.Avatar = gw.modifyAvatar(origmsg, dest) msg.Avatar = gw.modifyAvatar(origmsg, dest)
msg.Username = gw.modifyUsername(origmsg, dest) msg.Username = gw.modifyUsername(origmsg, dest)
@ -281,6 +281,7 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
} }
// append the message ID (mID) from this bridge (dest) to our brMsgIDs slice // append the message ID (mID) from this bridge (dest) to our brMsgIDs slice
if mID != "" { if mID != "" {
flog.Debugf("mID %s: %s", dest.Account, mID)
brMsgIDs = append(brMsgIDs, &BrMsgID{dest, mID, channel.ID}) brMsgIDs = append(brMsgIDs, &BrMsgID{dest, mID, channel.ID})
} }
} }