mirror of
https://github.com/pushbits/server.git
synced 2025-06-02 10:42:08 +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,10 +2,10 @@ package api
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/pushbits/server/internal/authentication"
|
||||
"github.com/pushbits/server/internal/log"
|
||||
"github.com/pushbits/server/internal/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -27,7 +27,7 @@ func (h *ApplicationHandler) generateToken(compat bool) string {
|
|||
}
|
||||
|
||||
func (h *ApplicationHandler) registerApplication(ctx *gin.Context, a *model.Application, u *model.User) error {
|
||||
log.Printf("Registering application %s.", a.Name)
|
||||
log.L.Printf("Registering application %s.", a.Name)
|
||||
|
||||
channelID, err := h.DP.RegisterApplication(a.ID, a.Name, a.Token, u.MatrixID)
|
||||
if success := successOrAbort(ctx, http.StatusInternalServerError, err); !success {
|
||||
|
@ -45,7 +45,7 @@ func (h *ApplicationHandler) registerApplication(ctx *gin.Context, a *model.Appl
|
|||
}
|
||||
|
||||
func (h *ApplicationHandler) createApplication(ctx *gin.Context, u *model.User, name string, compat bool) (*model.Application, error) {
|
||||
log.Printf("Creating application %s.", name)
|
||||
log.L.Printf("Creating application %s.", name)
|
||||
|
||||
application := model.Application{}
|
||||
application.Name = name
|
||||
|
@ -60,7 +60,7 @@ func (h *ApplicationHandler) createApplication(ctx *gin.Context, u *model.User,
|
|||
if err := h.registerApplication(ctx, &application, u); err != nil {
|
||||
err := h.DB.DeleteApplication(&application)
|
||||
if success := successOrAbort(ctx, http.StatusInternalServerError, err); !success {
|
||||
log.Printf("Cannot delete application with ID %d.", application.ID)
|
||||
log.L.Printf("Cannot delete application with ID %d.", application.ID)
|
||||
}
|
||||
|
||||
return nil, err
|
||||
|
@ -70,7 +70,7 @@ func (h *ApplicationHandler) createApplication(ctx *gin.Context, u *model.User,
|
|||
}
|
||||
|
||||
func (h *ApplicationHandler) deleteApplication(ctx *gin.Context, a *model.Application, u *model.User) error {
|
||||
log.Printf("Deleting application %s (ID %d).", a.Name, a.ID)
|
||||
log.L.Printf("Deleting application %s (ID %d).", a.Name, a.ID)
|
||||
|
||||
err := h.DP.DeregisterApplication(a, u)
|
||||
if success := successOrAbort(ctx, http.StatusInternalServerError, err); !success {
|
||||
|
@ -86,15 +86,15 @@ func (h *ApplicationHandler) deleteApplication(ctx *gin.Context, a *model.Applic
|
|||
}
|
||||
|
||||
func (h *ApplicationHandler) updateApplication(ctx *gin.Context, a *model.Application, updateApplication *model.UpdateApplication) error {
|
||||
log.Printf("Updating application %s (ID %d).", a.Name, a.ID)
|
||||
log.L.Printf("Updating application %s (ID %d).", a.Name, a.ID)
|
||||
|
||||
if updateApplication.Name != nil {
|
||||
log.Printf("Updating application name to '%s'.", *updateApplication.Name)
|
||||
log.L.Printf("Updating application name to '%s'.", *updateApplication.Name)
|
||||
a.Name = *updateApplication.Name
|
||||
}
|
||||
|
||||
if updateApplication.RefreshToken != nil && (*updateApplication.RefreshToken) {
|
||||
log.Print("Updating application token.")
|
||||
log.L.Print("Updating application token.")
|
||||
compat := updateApplication.StrictCompatibility != nil && (*updateApplication.StrictCompatibility)
|
||||
a.Token = h.generateToken(compat)
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ func (h *ApplicationHandler) CreateApplication(ctx *gin.Context) {
|
|||
var createApplication model.CreateApplication
|
||||
|
||||
if err := ctx.Bind(&createApplication); err != nil {
|
||||
log.Println(err)
|
||||
log.L.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
|
@ -12,6 +11,7 @@ import (
|
|||
"github.com/pushbits/server/internal/authentication/credentials"
|
||||
"github.com/pushbits/server/internal/configuration"
|
||||
"github.com/pushbits/server/internal/database"
|
||||
"github.com/pushbits/server/internal/log"
|
||||
"github.com/pushbits/server/internal/model"
|
||||
"github.com/pushbits/server/tests"
|
||||
"github.com/pushbits/server/tests/mockups"
|
||||
|
@ -50,7 +50,7 @@ func TestMain(m *testing.M) {
|
|||
db, err := mockups.GetEmptyDatabase(config.Crypto)
|
||||
if err != nil {
|
||||
cleanUp()
|
||||
log.Println("Can not set up database: ", err)
|
||||
log.L.Println("Can not set up database: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
TestDatabase = db
|
||||
|
@ -58,7 +58,7 @@ func TestMain(m *testing.M) {
|
|||
appHandler, err := getApplicationHandler(config)
|
||||
if err != nil {
|
||||
cleanUp()
|
||||
log.Println("Can not set up application handler: ", err)
|
||||
log.L.Println("Can not set up application handler: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ func TestMain(m *testing.M) {
|
|||
|
||||
// Run
|
||||
m.Run()
|
||||
log.Println("Clean up after Test")
|
||||
log.L.Println("Clean up after Test")
|
||||
cleanUp()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/pushbits/server/internal/authentication"
|
||||
"github.com/pushbits/server/internal/log"
|
||||
"github.com/pushbits/server/internal/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -45,7 +45,7 @@ type NotificationHandler struct {
|
|||
// @Router /message [post]
|
||||
func (h *NotificationHandler) CreateNotification(ctx *gin.Context) {
|
||||
application := authentication.GetApplication(ctx)
|
||||
log.Printf("Sending notification for application %s.", application.Name)
|
||||
log.L.Printf("Sending notification for application %s.", application.Name)
|
||||
|
||||
var notification model.Notification
|
||||
if err := ctx.Bind(¬ification); err != nil {
|
||||
|
@ -79,7 +79,7 @@ func (h *NotificationHandler) CreateNotification(ctx *gin.Context) {
|
|||
// @Router /message/{message_id} [DELETE]
|
||||
func (h *NotificationHandler) DeleteNotification(ctx *gin.Context) {
|
||||
application := authentication.GetApplication(ctx)
|
||||
log.Printf("Deleting notification for application %s.", application.Name)
|
||||
log.L.Printf("Deleting notification for application %s.", application.Name)
|
||||
|
||||
id, err := getMessageID(ctx)
|
||||
if success := successOrAbort(ctx, http.StatusUnprocessableEntity, err); !success {
|
||||
|
|
|
@ -2,10 +2,10 @@ package api
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/pushbits/server/internal/authentication"
|
||||
"github.com/pushbits/server/internal/log"
|
||||
"github.com/pushbits/server/internal/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -90,7 +90,7 @@ func (h *UserHandler) updateUser(ctx *gin.Context, u *model.User, updateUser mod
|
|||
}
|
||||
}
|
||||
|
||||
log.Printf("Updating user %s.", u.Name)
|
||||
log.L.Printf("Updating user %s.", u.Name)
|
||||
|
||||
if updateUser.Name != nil {
|
||||
u.Name = *updateUser.Name
|
||||
|
@ -146,7 +146,7 @@ func (h *UserHandler) CreateUser(ctx *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
log.Printf("Creating user %s.", createUser.Name)
|
||||
log.L.Printf("Creating user %s.", createUser.Name)
|
||||
|
||||
user, err := h.DB.CreateUser(createUser)
|
||||
|
||||
|
@ -232,7 +232,7 @@ func (h *UserHandler) DeleteUser(ctx *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
log.Printf("Deleting user %s.", user.Name)
|
||||
log.L.Printf("Deleting user %s.", user.Name)
|
||||
|
||||
if err := h.deleteApplications(ctx, user); err != nil {
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue