Replace even more zap occurences
This commit is contained in:
@@ -2,11 +2,11 @@ package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/apex/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/server"
|
||||
"go.uber.org/zap"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
@@ -40,6 +40,14 @@ func TrackedServerError(err error, s *server.Server) *RequestError {
|
||||
}
|
||||
}
|
||||
|
||||
func (e *RequestError) logger() *log.Entry {
|
||||
if e.server != nil {
|
||||
return e.server.Log().WithField("error_id", e.Uuid)
|
||||
}
|
||||
|
||||
return log.WithField("error_id", e.Uuid)
|
||||
}
|
||||
|
||||
// Sets the output message to display to the user in the error.
|
||||
func (e *RequestError) SetMessage(msg string) *RequestError {
|
||||
e.Message = msg
|
||||
@@ -61,19 +69,11 @@ func (e *RequestError) AbortWithStatus(status int, c *gin.Context) {
|
||||
|
||||
// Otherwise, log the error to zap, and then report the error back to the user.
|
||||
if status >= 500 {
|
||||
if e.server != nil {
|
||||
zap.S().Errorw("encountered error while handling HTTP request", zap.String("server", e.server.Uuid), zap.String("error_id", e.Uuid), zap.Error(e.Err))
|
||||
} else {
|
||||
zap.S().Errorw("encountered error while handling HTTP request", zap.String("error_id", e.Uuid), zap.Error(e.Err))
|
||||
}
|
||||
e.logger().WithField("error", e.Err).Error("encountered HTTP/500 error while handling request")
|
||||
|
||||
c.Error(errors.WithStack(e))
|
||||
} else {
|
||||
if e.server != nil {
|
||||
zap.S().Debugw("encountered error while handling HTTP request", zap.String("server", e.server.Uuid), zap.String("error_id", e.Uuid), zap.Error(e.Err))
|
||||
} else {
|
||||
zap.S().Debugw("encountered error while handling HTTP request", zap.String("error_id", e.Uuid), zap.Error(e.Err))
|
||||
}
|
||||
e.logger().WithField("error", e.Err).Debug("encountered non-HTTP/500 error while handling request")
|
||||
}
|
||||
|
||||
msg := "An unexpected error was encountered while processing this request."
|
||||
|
||||
@@ -2,6 +2,7 @@ package router
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/apex/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/server"
|
||||
@@ -74,15 +75,12 @@ func postServerPower(c *gin.Context) {
|
||||
// Pass the actual heavy processing off to a seperate thread to handle so that
|
||||
// we can immediately return a response from the server. Some of these actions
|
||||
// can take quite some time, especially stopping or restarting.
|
||||
go func() {
|
||||
if err := s.HandlePowerAction(data); err != nil {
|
||||
zap.S().Errorw(
|
||||
"encountered an error processing a server power action",
|
||||
zap.String("server", s.Uuid),
|
||||
zap.Error(err),
|
||||
)
|
||||
go func(server *server.Server) {
|
||||
if err := server.HandlePowerAction(data); err != nil {
|
||||
server.Log().WithFields(log.Fields{"action": data, "error": err}).
|
||||
Error("encountered error processing a server power action in the background")
|
||||
}
|
||||
}()
|
||||
}(s)
|
||||
|
||||
c.Status(http.StatusAccepted)
|
||||
}
|
||||
@@ -111,12 +109,7 @@ func postServerCommands(c *gin.Context) {
|
||||
|
||||
for _, command := range data.Commands {
|
||||
if err := s.Environment.SendCommand(command); err != nil {
|
||||
zap.S().Warnw(
|
||||
"failed to send command to server",
|
||||
zap.String("server", s.Uuid),
|
||||
zap.String("command", command),
|
||||
zap.Error(err),
|
||||
)
|
||||
s.Log().WithFields(log.Fields{"command": command, "error": err}).Warn("failed to send command to server instance")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
ws "github.com/gorilla/websocket"
|
||||
"github.com/pterodactyl/wings/router/websocket"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// Upgrades a connection to a websocket and passes events along between.
|
||||
@@ -40,7 +39,7 @@ func getServerWebsocket(c *gin.Context) {
|
||||
ws.CloseServiceRestart,
|
||||
ws.CloseAbnormalClosure,
|
||||
) {
|
||||
zap.S().Warnw("error handling websocket message", zap.Error(err))
|
||||
s.Log().WithField("error", err).Warn("error handling websocket message for server")
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -57,4 +56,3 @@ func getServerWebsocket(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ package router
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/apex/log"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/installer"
|
||||
"github.com/pterodactyl/wings/server"
|
||||
"github.com/pterodactyl/wings/system"
|
||||
"go.uber.org/zap"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -59,11 +59,7 @@ func postCreateServer(c *gin.Context) {
|
||||
i.Execute()
|
||||
|
||||
if err := i.Server().Install(); err != nil {
|
||||
zap.S().Errorw(
|
||||
"failed to run install process for server",
|
||||
zap.String("server", i.Uuid()),
|
||||
zap.Error(err),
|
||||
)
|
||||
log.WithFields(log.Fields{"server": i.Uuid(), "error": err}).Error("failed to run install process for server")
|
||||
}
|
||||
}(install)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package websocket
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/apex/log"
|
||||
"github.com/gbrlsnchs/jwt/v3"
|
||||
"github.com/google/uuid"
|
||||
"github.com/gorilla/websocket"
|
||||
@@ -10,7 +11,6 @@ import (
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/router/tokens"
|
||||
"github.com/pterodactyl/wings/server"
|
||||
"go.uber.org/zap"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -85,7 +85,6 @@ func (h *Handler) SendJson(v *Message) error {
|
||||
// If we're sending installation output but the user does not have the required
|
||||
// permissions to see the output, don't send it down the line.
|
||||
if v.Event == server.InstallOutputEvent {
|
||||
zap.S().Debugf("%+v", v.Args)
|
||||
if !j.HasPermission(PermissionReceiveInstall) {
|
||||
return nil
|
||||
}
|
||||
@@ -152,13 +151,8 @@ func (h *Handler) SendErrorJson(msg Message, err error) error {
|
||||
wsm.Args = []string{m}
|
||||
|
||||
if !server.IsSuspendedError(err) {
|
||||
zap.S().Errorw(
|
||||
"an error was encountered in the websocket process",
|
||||
zap.String("event", msg.Event),
|
||||
zap.String("server", h.server.Uuid),
|
||||
zap.String("error_identifier", u.String()),
|
||||
zap.Error(err),
|
||||
)
|
||||
h.server.Log().WithFields(log.Fields{"event": msg.Event, "error_identifier": u.String(), "error": err}).
|
||||
Error("failed to handle websocket process; an error was encountered processing an event")
|
||||
}
|
||||
|
||||
return h.unsafeSendJson(wsm)
|
||||
@@ -192,7 +186,7 @@ func (h *Handler) GetJwt() *tokens.WebsocketPayload {
|
||||
func (h *Handler) HandleInbound(m Message) error {
|
||||
if m.Event != AuthenticationEvent {
|
||||
if err := h.TokenValid(); err != nil {
|
||||
zap.S().Debugw("jwt token is no longer valid", zap.String("message", err.Error()))
|
||||
log.WithField("message", err.Error()).Debug("jwt for server websocket is no longer valid")
|
||||
|
||||
h.unsafeSendJson(Message{
|
||||
Event: ErrorEvent,
|
||||
|
||||
Reference in New Issue
Block a user