Go: move logger to common module (#14545)

### What problem does this PR solve?

As title

### Type of change

- [x] Refactoring

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-05-06 10:41:58 +08:00
committed by GitHub
parent 3a51c27a75
commit aa57b5bd8b
56 changed files with 628 additions and 717 deletions

View File

@@ -20,7 +20,6 @@ import (
"fmt"
"net/http"
"ragflow/internal/common"
"ragflow/internal/logger"
"ragflow/internal/server/local"
"ragflow/internal/service"
@@ -78,7 +77,7 @@ func (h *AuthHandler) AuthMiddleware() gin.HandlerFunc {
if !local.IsAdminAvailable() {
license := local.GetAdminStatus()
errMsg := fmt.Sprintf("server license %s", license.Reason)
logger.Warn(errMsg)
common.Warn(errMsg)
c.JSON(http.StatusServiceUnavailable, gin.H{
"code": common.CodeUnauthorized,
"message": errMsg,

View File

@@ -18,17 +18,16 @@ package handler
import (
"net/http"
"ragflow/internal/common"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"ragflow/internal/logger"
)
// HandleNoRoute handles requests to undefined routes
func HandleNoRoute(c *gin.Context) {
// Log the request details on server side
logger.Logger.Warn("The requested URL was not found",
common.Logger.Warn("The requested URL was not found",
zap.String("method", c.Request.Method),
zap.String("path", c.Request.URL.Path),
zap.String("query", c.Request.URL.RawQuery),

View File

@@ -21,7 +21,6 @@ import (
"net/http"
"ragflow/internal/common"
"ragflow/internal/engine"
"ragflow/internal/logger"
"ragflow/internal/service"
"github.com/gin-gonic/gin"
@@ -146,9 +145,9 @@ func (h *SkillSearchHandler) Search(c *gin.Context) {
// IndexSkillsRequest represents the request to index skills
type IndexSkillsRequest struct {
Skills []service.SkillInfo `json:"skills" binding:"required"`
SpaceID string `json:"space_id"`
EmbdID string `json:"embd_id"` // Optional, will use config's embd_id if empty
Skills []service.SkillInfo `json:"skills" binding:"required"`
SpaceID string `json:"space_id"`
EmbdID string `json:"embd_id"` // Optional, will use config's embd_id if empty
}
// IndexSkills handles the index skills request
@@ -191,7 +190,7 @@ func (h *SkillSearchHandler) IndexSkills(c *gin.Context) {
}
// Ensure index exists before indexing (for both ES and Infinity)
logger.Info("Ensuring skill index exists before indexing",
common.Info("Ensuring skill index exists before indexing",
zap.String("tenantID", user.ID),
zap.String("spaceID", req.SpaceID),
zap.String("engineType", h.docEngine.GetType()),
@@ -205,12 +204,12 @@ func (h *SkillSearchHandler) IndexSkills(c *gin.Context) {
}
if err := h.indexerService.BatchIndexSkills(c.Request.Context(), user.ID, req.SpaceID, req.Skills, h.docEngine, embdID); err != nil {
logger.Error(fmt.Sprintf("Failed to batch index skills: tenantID=%s, spaceID=%s, error=%v", user.ID, req.SpaceID, err), err)
common.Error(fmt.Sprintf("Failed to batch index skills: tenantID=%s, spaceID=%s, error=%v", user.ID, req.SpaceID, err), err)
jsonError(c, common.CodeOperatingError, err.Error())
return
}
logger.Info("Successfully indexed skills",
common.Info("Successfully indexed skills",
zap.String("tenantID", user.ID),
zap.String("spaceID", req.SpaceID),
zap.Int("indexedCount", len(req.Skills)))

View File

@@ -18,7 +18,7 @@ package handler
import (
"net/http"
"ragflow/internal/logger"
"ragflow/internal/common"
"ragflow/internal/server"
"ragflow/internal/service"
@@ -133,7 +133,7 @@ func (h *SystemHandler) GetVersion(c *gin.Context) {
// GetLogLevel returns the current log level
func (h *SystemHandler) GetLogLevel(c *gin.Context) {
level := logger.GetLevel()
level := common.GetLevel()
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "success",
@@ -157,7 +157,7 @@ func (h *SystemHandler) SetLogLevel(c *gin.Context) {
return
}
if err := logger.SetLevel(req.Level); err != nil {
if err := common.SetLevel(req.Level); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"message": err.Error(),