Handle logger levels
This commit is contained in:
parent
c996d71378
commit
72ecd20dd1
@ -12,6 +12,8 @@ import (
|
||||
const loggerMessage = "http_request"
|
||||
|
||||
func RequestLogger(logger *logrus.Logger) gin.HandlerFunc {
|
||||
debug := logger.Level > logrus.InfoLevel
|
||||
|
||||
return func(c *gin.Context) {
|
||||
start := time.Now()
|
||||
path := c.Request.URL.Path
|
||||
@ -20,7 +22,7 @@ func RequestLogger(logger *logrus.Logger) gin.HandlerFunc {
|
||||
c.Next()
|
||||
|
||||
// Skip logging static assets
|
||||
if strings.Contains(path, "/static/") {
|
||||
if strings.Contains(path, "/static/") && !debug {
|
||||
return
|
||||
}
|
||||
|
||||
@ -40,6 +42,11 @@ func RequestLogger(logger *logrus.Logger) gin.HandlerFunc {
|
||||
fields["error"] = err.Error()
|
||||
}
|
||||
|
||||
// Additional fields for debugging
|
||||
if debug {
|
||||
fields["raw_query"] = c.Request.URL.RawQuery
|
||||
}
|
||||
|
||||
entry := logrus.WithFields(fields)
|
||||
|
||||
switch {
|
||||
|
@ -184,9 +184,13 @@ func printVersion() {
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
router := gin.New()
|
||||
logger := logrus.New()
|
||||
if options.Debug {
|
||||
logger.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
|
||||
router.Use(api.RequestLogger(logrus.New()))
|
||||
router := gin.New()
|
||||
router.Use(api.RequestLogger(logger))
|
||||
router.Use(gin.Recovery())
|
||||
|
||||
// Enable HTTP basic authentication only if both user and password are set
|
||||
|
Loading…
x
Reference in New Issue
Block a user