feat: add dynamic log level adjustment APIs (#13850)

Add REST APIs to dynamically query and modify log levels at runtime for
both Python (Flask) and Go servers.

Changes:
- common/log_utils.py: add set_log_level() and get_log_levels()
functions
- admin/server/routes.py: add GET/PUT /api/v1/admin/log_levels endpoints
- api/apps/system_app.py: add GET/PUT /api/{version}/system/log_levels
endpoints
- internal/logger/logger.go: add GetLevel() and SetLevel() with atomic
level support
- internal/handler/system.go: add GetLogLevel, SetLogLevel, Health
handlers
- internal/router/router.go: route /health to systemHandler
- internal/admin/handler.go: add GetLogLevel, SetLogLevel handlers
- internal/admin/router.go: add /api/v1/admin/log_level routes

### What problem does this PR solve?

_Briefly describe what this PR aims to solve. Include background context
that will help reviewers understand the purpose of the PR._

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Zhichang Yu
2026-03-30 18:40:58 +08:00
committed by GitHub
parent 534729546e
commit 0d85a8e7aa
8 changed files with 237 additions and 10 deletions

View File

@@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"ragflow/internal/common"
"ragflow/internal/logger"
"ragflow/internal/server"
"ragflow/internal/service"
"ragflow/internal/utility"
@@ -1106,6 +1107,33 @@ func (h *Handler) HandleNoRoute(c *gin.Context) {
})
}
// GetLogLevel returns the current log level
func (h *Handler) GetLogLevel(c *gin.Context) {
level := logger.GetLevel()
success(c, gin.H{"level": level}, "")
}
// SetLogLevelRequest set log level request
type SetLogLevelRequest struct {
Level string `json:"level" binding:"required"`
}
// SetLogLevel sets the log level at runtime
func (h *Handler) SetLogLevel(c *gin.Context) {
var req SetLogLevelRequest
if err := c.ShouldBindJSON(&req); err != nil {
errorResponse(c, "level is required", 400)
return
}
if err := logger.SetLevel(req.Level); err != nil {
errorResponse(c, err.Error(), 400)
return
}
success(c, gin.H{"level": req.Level}, "Log level updated successfully")
}
// Reports handle heartbeat reports from servers
func (h *Handler) Reports(c *gin.Context) {
var req common.BaseMessage