mirror of
https://github.com/pushbits/server.git
synced 2025-07-26 21:08:04 +02:00
Use logrus for logging
This commit is contained in:
parent
c96baf40a5
commit
f839f248b9
19 changed files with 192 additions and 87 deletions
|
@ -2,11 +2,11 @@ package dispatcher
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/pushbits/server/internal/log"
|
||||
"github.com/pushbits/server/internal/model"
|
||||
"maunium.net/go/mautrix"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/event"
|
||||
mId "maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
@ -17,7 +17,7 @@ func buildRoomTopic(id uint) string {
|
|||
|
||||
// RegisterApplication creates a channel for an application.
|
||||
func (d *Dispatcher) RegisterApplication(id uint, name, token, user string) (string, error) {
|
||||
log.Printf("Registering application %s, notifications will be relayed to user %s.\n", name, user)
|
||||
log.L.Printf("Registering application %s, notifications will be relayed to user %s.\n", name, user)
|
||||
|
||||
resp, err := d.mautrixClient.CreateRoom(&mautrix.ReqCreateRoom{
|
||||
Visibility: "private",
|
||||
|
@ -28,18 +28,18 @@ func (d *Dispatcher) RegisterApplication(id uint, name, token, user string) (str
|
|||
Topic: buildRoomTopic(id),
|
||||
})
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
log.L.Print(err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
log.Printf("Application %s is now relayed to room with ID %s.\n", name, resp.RoomID.String())
|
||||
log.L.Printf("Application %s is now relayed to room with ID %s.\n", name, resp.RoomID.String())
|
||||
|
||||
return resp.RoomID.String(), err
|
||||
}
|
||||
|
||||
// DeregisterApplication deletes a channel for an application.
|
||||
func (d *Dispatcher) DeregisterApplication(a *model.Application, u *model.User) error {
|
||||
log.Printf("Deregistering application %s (ID %d) with Matrix ID %s.\n", a.Name, a.ID, a.MatrixID)
|
||||
log.L.Printf("Deregistering application %s (ID %d) with Matrix ID %s.\n", a.Name, a.ID, a.MatrixID)
|
||||
|
||||
// The user might have left the channel, but we can still try to remove them.
|
||||
|
||||
|
@ -47,17 +47,17 @@ func (d *Dispatcher) DeregisterApplication(a *model.Application, u *model.User)
|
|||
Reason: "This application was deleted",
|
||||
UserID: mId.UserID(u.MatrixID),
|
||||
}); err != nil {
|
||||
log.Print(err)
|
||||
log.L.Print(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := d.mautrixClient.LeaveRoom(mId.RoomID(a.MatrixID)); err != nil {
|
||||
log.Print(err)
|
||||
log.L.Print(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := d.mautrixClient.ForgetRoom(mId.RoomID(a.MatrixID)); err != nil {
|
||||
log.Print(err)
|
||||
log.L.Print(err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ func (d *Dispatcher) DeregisterApplication(a *model.Application, u *model.User)
|
|||
|
||||
func (d *Dispatcher) sendRoomEvent(roomID, eventType string, content interface{}) error {
|
||||
if _, err := d.mautrixClient.SendStateEvent(mId.RoomID(roomID), event.NewEventType(eventType), "", content); err != nil {
|
||||
log.Print(err)
|
||||
log.L.Print(err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ func (d *Dispatcher) sendRoomEvent(roomID, eventType string, content interface{}
|
|||
|
||||
// UpdateApplication updates a channel for an application.
|
||||
func (d *Dispatcher) UpdateApplication(a *model.Application) error {
|
||||
log.Printf("Updating application %s (ID %d) with Matrix ID %s.\n", a.Name, a.ID, a.MatrixID)
|
||||
log.L.Printf("Updating application %s (ID %d) with Matrix ID %s.\n", a.Name, a.ID, a.MatrixID)
|
||||
|
||||
content := map[string]interface{}{
|
||||
"name": a.Name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue