aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-27 10:35:09 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-27 10:35:09 +0100
commit19975e981ed0f1fbd96644d95ede5435bfbdccfc (patch)
tree02c0b5df7583f212de9dfe9dbebff1e6fc8160fd
parent6bbf08af8f8acc93d6aed721f56d70c8aca75ed4 (diff)
downloadeasybridge-19975e981ed0f1fbd96644d95ede5435bfbdccfc.tar.gz
easybridge-19975e981ed0f1fbd96644d95ede5435bfbdccfc.zip
Logging done better
-rw-r--r--account.go10
-rw-r--r--connector/mattermost/mattermost.go9
-rw-r--r--db.go10
-rw-r--r--mxlib/client.go8
-rw-r--r--server.go5
5 files changed, 20 insertions, 22 deletions
diff --git a/account.go b/account.go
index 9e18ec1..c7f30f0 100644
--- a/account.go
+++ b/account.go
@@ -215,7 +215,7 @@ func (a *Account) joinedInternal(roomId RoomID) error {
return err
}
- log.Debugf("Joined %s (%s)\n", roomId, a.MatrixUser)
+ log.Tracef("Joined %s (%s)\n", roomId, a.MatrixUser)
err = mx.RoomInvite(mx_room_id, a.MatrixUser)
if err != nil && strings.Contains(err.Error(), "already in the room") {
@@ -248,7 +248,7 @@ func (a *Account) leftInternal(roomId RoomID) error {
return err
}
- log.Printf("Left %s (%s)\n", roomId, a.MatrixUser)
+ log.Tracef("Left %s (%s)\n", roomId, a.MatrixUser)
err = mx.RoomKick(mx_room_id, a.MatrixUser, fmt.Sprintf("got leave room event on %s", a.Protocol))
if err != nil && strings.Contains(err.Error(), "not in the room") {
@@ -366,7 +366,7 @@ func (a *Account) eventInternal(event *Event) error {
}
if event.Type == EVENT_JOIN {
- log.Printf("%s join %s %s", a.Protocol, event.Author, event.Room)
+ log.Tracef("%s join %s %s", a.Protocol, event.Author, event.Room)
mx_room_id, err := dbGetMxRoom(a.Protocol, event.Room)
if err != nil {
return err
@@ -382,7 +382,7 @@ func (a *Account) eventInternal(event *Event) error {
return mx.RoomJoinAs(mx_room_id, mx_user_id)
} else if event.Type == EVENT_LEAVE {
- log.Printf("%s join %s %s", a.Protocol, event.Author, event.Room)
+ log.Tracef("%s join %s %s", a.Protocol, event.Author, event.Room)
mx_room_id, err := dbGetMxRoom(a.Protocol, event.Room)
if err != nil {
return err
@@ -390,7 +390,7 @@ func (a *Account) eventInternal(event *Event) error {
return mx.RoomLeaveAs(mx_room_id, mx_user_id)
} else {
- log.Printf("%s msg %s %s", a.Protocol, event.Author, event.Room)
+ log.Tracef("%s msg %s %s", a.Protocol, event.Author, event.Room)
mx_room_id := ""
if len(event.Room) > 0 {
diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go
index e3a6429..530938c 100644
--- a/connector/mattermost/mattermost.go
+++ b/connector/mattermost/mattermost.go
@@ -109,8 +109,6 @@ func (mm *Mattermost) Configure(c Configuration) error {
go mm.conn.WsReceiver()
go mm.conn.StatusLoop()
- fmt.Printf("CLIENT4: %#v\n", mm.conn.Client)
-
for i := 0; i < 42; i++ {
time.Sleep(time.Duration(1) * time.Second)
if mm.conn.WsConnected {
@@ -166,7 +164,6 @@ func (mm *Mattermost) reverseRoomId(id string) (bool, RoomID) {
teamName := mm.conn.GetTeamName(team)
if u, ok := mm.teams[teamName]; ok && u {
name := mm.conn.GetChannelName(id)
- fmt.Printf("CHANNEL NAME: %s TEAM: %s\n", name, teamName)
return true, RoomID(fmt.Sprintf("%s@%s@%s", name, teamName, mm.server))
} else {
return false, ""
@@ -329,7 +326,7 @@ func (mm *Mattermost) handleConnected() {
mm.caches.sentjoined = make(map[string]bool)
mm.caches.displayname = make(map[UserID]string)
- fmt.Printf("Connected to mattermost\n")
+ log.Debugf("Connected to mattermost: %s@%s\n", mm.username, mm.server)
// Handle incoming messages
go mm.handleLoop(mm.conn.MessageChan, mm.handlerStopChan)
@@ -468,8 +465,8 @@ func (mm *Mattermost) handleLoop(msgCh chan *matterclient.Message, quitCh chan b
case <-quitCh:
break
case msg := <-msgCh:
- fmt.Printf("Mattermost: %#v\n", msg)
- fmt.Printf("Mattermost raw: %#v\n", msg.Raw)
+ log.Tracef("Mattermost: %#v\n", msg)
+ log.Tracef("Mattermost raw: %#v\n", msg.Raw)
err := mm.handlePosted(msg.Raw)
if err != nil {
log.Warnf("Mattermost error: %s", err)
diff --git a/db.go b/db.go
index c5f74ef..9090626 100644
--- a/db.go
+++ b/db.go
@@ -180,7 +180,7 @@ func dbGetMxRoom(protocol string, roomId connector.RoomID) (string, error) {
mx_room_id, err = mx.CreateRoom(name, alias, []string{})
if err != nil {
- log.Printf("Could not create room for %s: %s", name, err)
+ log.Warnf("Could not create room for %s: %s", name, err)
return "", err
}
}
@@ -192,7 +192,7 @@ func dbGetMxRoom(protocol string, roomId connector.RoomID) (string, error) {
}
db.Create(&room)
}
- log.Debugf("Got room id: %s", room.MxRoomID)
+ log.Tracef("Got room id for %s %s: %s", protocol, roomId, room.MxRoomID)
return room.MxRoomID, nil
}
@@ -215,7 +215,7 @@ func dbGetMxPmRoom(protocol string, them connector.UserID, themMxId string, usMx
mx_room_id, err := mx.CreateDirectRoomAs([]string{usMxId}, themMxId)
if err != nil {
- log.Printf("Could not create room for %s: %s", name, err)
+ log.Warnf("Could not create room for %s: %s", name, err)
return "", err
}
@@ -234,7 +234,7 @@ func dbGetMxPmRoom(protocol string, them connector.UserID, themMxId string, usMx
}
db.Create(&room)
}
- log.Debugf("Got PM room id: %s", room.MxRoomID)
+ log.Tracef("Got PM room id for %s %s %s %s: %s", usMxId, protocol, usAccount, them, room.MxRoomID)
return room.MxRoomID, nil
}
@@ -256,7 +256,7 @@ func dbGetMxUser(protocol string, userId connector.UserID) (string, error) {
err := mx.RegisterUser(username)
if err != nil {
if mxE, ok := err.(*mxlib.MxError); !ok || mxE.ErrCode != "M_USER_IN_USE" {
- log.Printf("Could not register %s: %s", username, err)
+ log.Warnf("Could not register %s: %s", username, err)
return "", err
}
}
diff --git a/mxlib/client.go b/mxlib/client.go
index e382ddd..71bba3f 100644
--- a/mxlib/client.go
+++ b/mxlib/client.go
@@ -50,7 +50,7 @@ func (mx *Client) PutApiCall(endpoint string, data interface{}, response interfa
return err
}
- log.Debugf("Matrix PUT request: %s %s\n", endpoint, string(body))
+ log.Debugf("Matrix PUT request: %s\n", endpoint)
req, err := http.NewRequest("PUT", mx.Server+endpoint, bytes.NewBuffer(body))
if err != nil {
@@ -67,7 +67,7 @@ func (mx *Client) PostApiCall(endpoint string, data interface{}, response interf
return err
}
- log.Debugf("Matrix POST request: %s %s\n", endpoint, string(body))
+ log.Debugf("Matrix POST request: %s\n", endpoint)
req, err := http.NewRequest("POST", mx.Server+endpoint, bytes.NewBuffer(body))
if err != nil {
@@ -94,7 +94,7 @@ func (mx *Client) DoAndParse(req *http.Request, response interface{}) error {
if err != nil {
return err
}
- log.Debugf("Response (%d): %#v\n", resp.StatusCode, e)
+ log.Debugf("Response: %d %#v\n", resp.StatusCode, e)
return &e
}
@@ -103,7 +103,7 @@ func (mx *Client) DoAndParse(req *http.Request, response interface{}) error {
return err
}
- log.Debugf("Response: %#v\n", response)
+ log.Debugf("Response: 200 OK")
return nil
}
diff --git a/server.go b/server.go
index c61ad7f..309ac34 100644
--- a/server.go
+++ b/server.go
@@ -65,7 +65,7 @@ func checkTokenAndLog(handler http.Handler) http.Handler {
return
}
- log.Printf("%s %s %s\n", r.RemoteAddr, r.Method, r.URL)
+ log.Printf("%s %s %s\n", r.RemoteAddr, r.Method, strings.Split(r.URL, "?")[0])
handler.ServeHTTP(w, r)
})
}
@@ -80,7 +80,8 @@ func handleTxn(w http.ResponseWriter, r *http.Request) {
return
}
- log.Debugf("Got transaction %#v\n", txn)
+ log.Debugf("Processing transaction %s (%d events)", mux.Vars(r)["txnId"], len(txn.Events))
+ log.Tracef("Transaction content: %#v\n", txn)
for i := range txn.Events {
ev := &txn.Events[i]