Cleaner gin logging in debug
This commit is contained in:
parent
b03aa20c8d
commit
495ad4defd
|
@ -4,7 +4,6 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/mitchellh/colorstring"
|
"github.com/mitchellh/colorstring"
|
||||||
"github.com/pterodactyl/wings/loggers/cli"
|
"github.com/pterodactyl/wings/loggers/cli"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -224,8 +223,6 @@ func rootCmdRun(*cobra.Command, []string) {
|
||||||
"port": c.Api.Port,
|
"port": c.Api.Port,
|
||||||
}).Info("configuring webserver...")
|
}).Info("configuring webserver...")
|
||||||
|
|
||||||
gin.SetMode("release")
|
|
||||||
|
|
||||||
r := router.Configure()
|
r := router.Configure()
|
||||||
addr := fmt.Sprintf("%s:%d", c.Api.Host, c.Api.Port)
|
addr := fmt.Sprintf("%s:%d", c.Api.Host, c.Api.Port)
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,32 @@
|
||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/apex/log"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Configures the routing infrastructure for this daemon instance.
|
// Configures the routing infrastructure for this daemon instance.
|
||||||
func Configure() *gin.Engine {
|
func Configure() *gin.Engine {
|
||||||
router := gin.Default()
|
gin.SetMode("release")
|
||||||
|
|
||||||
|
router := gin.New()
|
||||||
|
|
||||||
|
router.Use(gin.Recovery())
|
||||||
router.Use(SetAccessControlHeaders)
|
router.Use(SetAccessControlHeaders)
|
||||||
|
// @todo log this into a different file so you can setup IP blocking for abusive requests and such.
|
||||||
|
// This should still dump requests in debug mode since it does help with understanding the request
|
||||||
|
// lifecycle and quickly seeing what was called leading to the logs. However, it isn't feasible to mix
|
||||||
|
// this output in production and still get meaningful logs from it since they'll likely just be a huge
|
||||||
|
// spamfest.
|
||||||
|
router.Use(gin.LoggerWithFormatter(func(params gin.LogFormatterParams) string {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"client_ip": params.ClientIP,
|
||||||
|
"status": params.StatusCode,
|
||||||
|
"latency": params.Latency,
|
||||||
|
}).Debugf("%s %s", params.MethodColor()+params.Method+params.ResetColor(), params.Path)
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}))
|
||||||
|
|
||||||
router.OPTIONS("/api/system", func(c *gin.Context) {
|
router.OPTIONS("/api/system", func(c *gin.Context) {
|
||||||
c.Status(200)
|
c.Status(200)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user