RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
refactor(go): unify Go logging on the zap logger (#20026)
jay77721338703565a5c
diff --git a/internal/admin/service.go b/internal/admin/service.goindex 22eebc2504..a0570f987d 100644--- a/internal/admin/service.go+++ b/internal/admin/service.go@@ -1393,7 +1393,7 @@ func (s *Service) GetVariable(ctx context.Context, varName string) ([]map[stringreturn nil, NewAdminException("Can't get setting: " + varName)}}- return common.FormatSystemSettings(settings), nil+ return entity.FormatSystemSettings(settings), nil}// ListAllVariables list all variables@@ -1404,7 +1404,7 @@ func (s *Service) ListAllVariables(ctx context.Context) ([]map[string]interface{return nil, err}- return common.FormatSystemSettings(settings), nil+ return entity.FormatSystemSettings(settings), nil}// SetVariable set variable@@ -1422,7 +1422,7 @@ func (s *Service) setVariable(ctx context.Context, db *gorm.DB, varName, varValuif len(settings) == 1 {setting := &settings[0]- if err = common.ValidateSystemSettingValue(*setting, varValue); err != nil {+ if err = entity.ValidateSystemSettingValue(*setting, varValue); err != nil {return err}setting.Value = varValue@@ -1431,14 +1431,14 @@ func (s *Service) setVariable(ctx context.Context, db *gorm.DB, varName, varValureturn NewAdminException("Can't update more than 1 setting: " + varName)}- dataType := common.InferSystemSettingDataType(varName)+ dataType := entity.InferSystemSettingDataType(varName)newSetting := &entity.SystemSettings{Name: varName,Value: varValue,Source: "admin",DataType: dataType,}- if err = common.ValidateSystemSettingValue(*newSetting, varValue); err != nil {+ if err = entity.ValidateSystemSettingValue(*newSetting, varValue); err != nil {return err}return s.systemSettingsDAO.Create(ctx, db, newSetting)diff --git a/internal/admin/service_variables_test.go b/internal/admin/service_variables_test.goindex 238ad59fc7..2408892747 100644--- a/internal/admin/service_variables_test.go+++ b/internal/admin/service_variables_test.go@@ -17,7 +17,6 @@package adminimport (- "ragflow/internal/common""ragflow/internal/entity""testing")@@ -43,7 +42,7 @@ func TestValidateSystemSettingValue(t *testing.T) {for _, tt := range tests {t.Run(tt.name, func(t *testing.T) {setting := entity.SystemSettings{Name: "test.setting", DataType: tt.dataType}- err := common.ValidateSystemSettingValue(setting, tt.value)+ err := entity.ValidateSystemSettingValue(setting, tt.value)if (err != nil) != tt.wantError {t.Fatalf("validateSystemSettingValue() error = %v, wantError %v", err, tt.wantError)}@@ -60,7 +59,7 @@ func TestInferSystemSettingDataType(t *testing.T) {}for name, want := range tests {- if got := common.InferSystemSettingDataType(name); got != want {+ if got := entity.InferSystemSettingDataType(name); got != want {t.Fatalf("inferSystemSettingDataType(%q) = %q, want %q", name, got, want)}}diff --git a/internal/agent/sandbox/probe.go b/internal/agent/sandbox/probe.goindex b541d8b437..7c431e9e68 100644--- a/internal/agent/sandbox/probe.go+++ b/internal/agent/sandbox/probe.go@@ -4,9 +4,12 @@ import ("context""errors""fmt"- "log""strings""time"++ "go.uber.org/zap"++ "ragflow/internal/common")const connectionProbeCode = `import json@@ -55,7 +58,7 @@ func testConnectionWithProvider(ctx context.Context, provider SandboxProvider) (defer cancel()if err := provider.DestroyInstance(cleanupCtx, inst); err != nil {// Do not include provider configuration or upstream error material.- log.Printf("sandbox connection probe cleanup failed: provider=%s", provider.ProviderType())+ common.Warn("sandbox: connection probe cleanup failed", zap.String("provider", string(provider.ProviderType())))}}()diff --git a/internal/agent/tool/dataset_navigation.go b/internal/agent/tool/dataset_navigation.goindex 297bdd4e2e..3e09fc4f68 100644--- a/internal/agent/tool/dataset_navigation.go+++ b/internal/agent/tool/dataset_navigation.go@@ -20,13 +20,14 @@ import ("context""encoding/json""fmt"- "log""sort""strings"einotool "github.com/cloudwego/eino/components/tool""github.com/cloudwego/eino/schema"+ "go.uber.org/zap"+ "ragflow/internal/common""ragflow/internal/dao""ragflow/internal/service/nav")@@ -234,7 +235,7 @@ func (d *DatasetNavigationByTree) InvokableRun(ctx context.Context, argumentsInJRetrievalFrom: "dataset",})if err != nil {- log.Printf("[Dataset navigation] content-recall retrieval failed: %v", err)+ common.Warn("dataset navigation: content-recall retrieval failed", zap.Error(err))} else {// Python :557-563 — the retrieval's doc_aggs read in order; the ES// aggregation orders by hit count descending, so the same order is@@ -252,7 +253,7 @@ func (d *DatasetNavigationByTree) InvokableRun(ctx context.Context, argumentsInJcounts[did]++}sort.SliceStable(order, func(i, j int) bool { return counts[order[i]] > counts[order[j]] })- log.Printf("[Dataset navigation] Content recall found %d candidate doc(s).", len(order))+ common.Info("dataset navigation: content recall found candidates", zap.Int("docs", len(order)))for _, did := range order {collect(did)}diff --git a/internal/channels/bootstrap.go b/internal/channels/bootstrap.goindex 24dca10fe3..0f46295ee0 100644--- a/internal/channels/bootstrap.go+++ b/internal/channels/bootstrap.go@@ -22,11 +22,13 @@ import ("encoding/hex""encoding/json""fmt"- "log""sync""time"+ "go.uber.org/zap"+"ragflow/internal/channels/core"+ "ragflow/internal/common""ragflow/internal/dao""ragflow/internal/entity""ragflow/internal/service"@@ -85,7 +87,7 @@ func (r *Runtime) Run(ctx context.Context) {// check channel's status periodicallyfor {if err := r.Reconcile(ctx); err != nil {- log.Printf("chat channel reconcile failed: %v", err)+ common.Error("chat channel reconcile failed", err)}select {case <-ctx.Done():@@ -133,7 +135,7 @@ func (r *Runtime) Reconcile(ctx context.Context) error {}}if err = syncWhatsAppGateway(ctx, activeWhatsApp); err != nil && activeWhatsApp {- log.Printf("failed to sync WhatsApp gateway: %v", err)+ common.Error("failed to sync WhatsApp gateway", err)reconcileErr = fmt.Errorf("sync WhatsApp gateway: %w", err)}@@ -148,7 +150,7 @@ func (r *Runtime) Reconcile(ctx context.Context) error {continue}if err = r.startChannel(ctx, accountID, wanted); err != nil {- log.Printf("failed to start chat channel %s (%s): %v", accountID, wanted.channel, err)+ common.Error("failed to start chat channel", err, zap.String("account_id", accountID), zap.String("channel", wanted.channel))r.recordStartFailure(accountID, wanted.fingerprint, now)if reconcileErr == nil {reconcileErr = fmt.Errorf("failed to start chat channel %s: %w", accountID, err)@@ -282,7 +284,7 @@ func (r *Runtime) startChannel(ctx context.Context, accountID string, wanted desr.mu.Lock()r.running[accountID] = runningChannel{channel: ch, fingerprint: wanted.fingerprint}r.mu.Unlock()- log.Printf("started chat channel %s:%s", ch.ChannelID(), accountID)+ common.Info("started chat channel", zap.String("channel", ch.ChannelID()), zap.String("account_id", accountID))return nil}@@ -346,6 +348,6 @@ func (r *Runtime) stopAll(ctx context.Context) {// stopChannel stops one platform channel and logs any shutdown error.func stopChannel(ctx context.Context, ch core.Channel) {if err := ch.Stop(ctx); err != nil {- log.Printf("failed to stop chat channel %s:%s: %v", ch.ChannelID(), ch.AccountID(), err)+ common.Error("failed to stop chat channel", err, zap.String("channel", ch.ChannelID()), zap.String("account_id", ch.AccountID()))}}diff --git a/internal/channels/dingtalk.go b/internal/channels/dingtalk.goindex d37f03f0eb..0968942ec0 100644--- a/internal/channels/dingtalk.go+++ b/internal/channels/dingtalk.go@@ -25,7 +25,6 @@ import ("errors""fmt""io"- "log""net/http""strconv""strings"@@ -35,8 +34,10 @@ import ("github.com/open-dingtalk/dingtalk-stream-sdk-go/chatbot""github.com/open-dingtalk/dingtalk-stream-sdk-go/clientV2""github.com/open-dingtalk/dingtalk-stream-sdk-go/payload"+ "go.uber.org/zap""ragflow/internal/channels/core"+ "ragflow/internal/common")const (@@ -190,7 +191,7 @@ func (c *dingTalkChannel) Send(ctx context.Context, msg core.OutgoingMessage) ersessionWebhook := c.sessionWebhooks[msg.ChatID]c.mu.Unlock()if strings.TrimSpace(sessionWebhook) == "" {- log.Printf("[dingtalk:%s] no sessionWebhook cached for chat_id=%s; dropping reply", c.account.AccountID, msg.ChatID)+ common.Warn("dingtalk: no sessionWebhook cached, dropping reply", zap.String("account_id", c.account.AccountID), zap.String("chat_id", msg.ChatID))return nil}@@ -225,11 +226,11 @@ func (c *dingTalkChannel) run(ctx context.Context) {c.mu.Unlock()}()if c.stream == nil {- log.Printf("[dingtalk:%s] stream client is not initialized", c.account.AccountID)+ common.Warn("dingtalk: stream client is not initialized", zap.String("account_id", c.account.AccountID))return}if err := c.stream.Start(ctx); err != nil && ctx.Err() == nil {- log.Printf("[dingtalk:%s] stream client exited: %v", c.account.AccountID, err)+ common.Error("dingtalk: stream client exited", err, zap.String("account_id", c.account.AccountID))}}@@ -246,7 +247,7 @@ func (c *dingTalkChannel) handleBotCallback(data *chatbot.BotCallbackDataModel)return &chatbot.BotCallbackRespModel{}, nil}if dedupKey != "" && !c.beginMessage(dedupKey) {- log.Printf("[dingtalk:%s] skipping duplicate message=%s", c.account.AccountID, dedupKey)+ common.Info("dingtalk: skipping duplicate message", zap.String("account_id", c.account.AccountID), zap.String("dedup_key", dedupKey))return &chatbot.BotCallbackRespModel{}, nil}if !c.enqueueIncoming(ctx, dingTalkQueuedMessage{incoming: incoming, dedupKey: dedupKey}) && dedupKey != "" {@@ -327,7 +328,7 @@ func (c *dingTalkChannel) enqueueIncoming(ctx context.Context, item dingTalkQueugo c.runWorker(ctx, item.incoming.ChatID, worker)}if queueFull {- log.Printf("[dingtalk:%s] dropping message %s for chat %s: queue is full", c.account.AccountID, item.incoming.MessageID, item.incoming.ChatID)+ common.Warn("dingtalk: dropping message, queue is full", zap.String("account_id", c.account.AccountID), zap.String("message_id", item.incoming.MessageID), zap.String("chat_id", item.incoming.ChatID))}return false}@@ -382,7 +383,7 @@ func (c *dingTalkChannel) handleIncoming(ctx context.Context, incoming core.Incoreturn}if err := handler(ctx, incoming); err != nil {- log.Printf("[dingtalk:%s] message handler error: %v", c.account.AccountID, err)+ common.Error("dingtalk: message handler error", err, zap.String("account_id", c.account.AccountID))}}diff --git a/internal/channels/discord.go b/internal/channels/discord.goindex 0216b1858f..3df964ccb3 100644--- a/internal/channels/discord.go+++ b/internal/channels/discord.go@@ -23,7 +23,6 @@ import ("errors""fmt""io"- "log""net/http""net/url""strconv"@@ -33,8 +32,10 @@ import ("time""github.com/gorilla/websocket"+ "go.uber.org/zap""ragflow/internal/channels/core"+ "ragflow/internal/common")const (@@ -281,7 +282,7 @@ func (c *discordChannel) Send(ctx context.Context, msg core.OutgoingMessage) errfunc (c *discordChannel) run(ctx context.Context) {for ctx.Err() == nil {if err := c.runGateway(ctx); err != nil && ctx.Err() == nil {- log.Printf("[discord:%s] gateway error: %v", c.account.AccountID, err)+ common.Error("discord: gateway error", err, zap.String("account_id", c.account.AccountID))}if ctx.Err() != nil {return@@ -440,7 +441,7 @@ func (c *discordChannel) handleDispatch(ctx context.Context, payload discordGatec.selfID = ready.User.IDc.mu.Unlock()- log.Printf("[discord:%s] connected as bot id %s", c.account.AccountID, ready.User.ID)+ common.Info("discord: connected", zap.String("account_id", c.account.AccountID), zap.String("bot_id", ready.User.ID))case "MESSAGE_CREATE":c.handleMessageCreate(ctx, payload.D)}@@ -532,7 +533,7 @@ func (c *discordChannel) enqueueIncoming(ctx context.Context, incoming core.Inco}if queueFull {- log.Printf("[discord:%s] dropping message %s for chat %s: queue is full", c.account.AccountID, incoming.MessageID, incoming.ChatID)+ common.Warn("discord: dropping message, queue is full", zap.String("account_id", c.account.AccountID), zap.String("message_id", incoming.MessageID), zap.String("chat_id", incoming.ChatID))}return false@@ -589,7 +590,7 @@ func (c *discordChannel) handleIncoming(ctx context.Context, incoming core.Incomreturn}if err := handler(ctx, incoming); err != nil {- log.Printf("[discord:%s] message handler error: %v", c.account.AccountID, err)+ common.Error("discord: message handler error", err, zap.String("account_id", c.account.AccountID))}}diff --git a/internal/channels/feishu.go b/internal/channels/feishu.goindex ba23fe9ee2..fe8693aea8 100644--- a/internal/channels/feishu.go+++ b/internal/channels/feishu.go@@ -21,7 +21,6 @@ import ("encoding/json""errors""fmt"- "log""strconv""strings""sync"@@ -32,8 +31,10 @@ import ("github.com/larksuite/oapi-sdk-go/v3/event/dispatcher"larkim "github.com/larksuite/oapi-sdk-go/v3/service/im/v1"larkws "github.com/larksuite/oapi-sdk-go/v3/ws"+ "go.uber.org/zap""ragflow/internal/channels/core"+ "ragflow/internal/common")const (@@ -223,11 +224,11 @@ func (c *feishuChannel) Send(ctx context.Context, msg core.OutgoingMessage) erro// run keeps the SDK WebSocket client active until the channel stops.func (c *feishuChannel) run(ctx context.Context) {if c.wsClient == nil {- log.Printf("[feishu:%s] WebSocket client is not initialized", c.account.AccountID)+ common.Warn("feishu: WebSocket client is not initialized", zap.String("account_id", c.account.AccountID))return}if err := c.wsClient.Start(ctx); err != nil && ctx.Err() == nil {- log.Printf("[feishu:%s] WebSocket client exited: %v", c.account.AccountID, err)+ common.Error("feishu: WebSocket client exited", err, zap.String("account_id", c.account.AccountID))}}@@ -317,7 +318,7 @@ func (c *feishuChannel) enqueueIncoming(incoming core.IncomingMessage) bool {go c.runWorker(c.ctx, incoming.ChatID, worker)}if queueFull {- log.Printf("[feishu:%s] dropping message %s for chat %s: queue is full", c.account.AccountID, incoming.MessageID, incoming.ChatID)+ common.Warn("feishu: dropping message, queue is full", zap.String("account_id", c.account.AccountID), zap.String("message_id", incoming.MessageID), zap.String("chat_id", incoming.ChatID))}return false}@@ -371,7 +372,7 @@ func (c *feishuChannel) handleIncoming(ctx context.Context, incoming core.Incomireturn}if err := handler(ctx, incoming); err != nil {- log.Printf("[feishu:%s] message handler error: %v", c.account.AccountID, err)+ common.Error("feishu: message handler error", err, zap.String("account_id", c.account.AccountID))}}diff --git a/internal/channels/line.go b/internal/channels/line.goindex 5491a0b6bb..c89e04a2e4 100644--- a/internal/channels/line.go+++ b/internal/channels/line.go@@ -26,7 +26,6 @@ import ("errors""fmt""io"- "log""net""net/http""strconv"@@ -34,7 +33,10 @@ import ("sync""time"+ "go.uber.org/zap"+"ragflow/internal/channels/core"+ "ragflow/internal/common")const (@@ -189,7 +191,7 @@ func (c *lineChannel) Start(ctx context.Context) error {c.mu.Lock()c.server = serverc.mu.Unlock()- log.Printf("[line:%s] registered at path /line/%s/webhook", c.account.AccountID, c.account.AccountID)+ common.Info("line: registered webhook", zap.String("account_id", c.account.AccountID))return nil}@@ -323,7 +325,7 @@ func (c *lineChannel) enqueueIncoming(incoming core.IncomingMessage) bool {go c.runWorker(ctx, incoming.ChatID, worker)}if queueFull {- log.Printf("[line:%s] dropping message %s for chat %s: queue is full", c.account.AccountID, incoming.MessageID, incoming.ChatID)+ common.Warn("line: dropping message, queue is full", zap.String("account_id", c.account.AccountID), zap.String("message_id", incoming.MessageID), zap.String("chat_id", incoming.ChatID))}return false}@@ -374,7 +376,7 @@ func (c *lineChannel) handleIncoming(ctx context.Context, incoming core.Incomingreturn}if err := handler(ctx, incoming); err != nil {- log.Printf("[line:%s] message handler error: %v", c.account.AccountID, err)+ common.Error("line: message handler error", err, zap.String("account_id", c.account.AccountID))}}@@ -493,10 +495,10 @@ func (s *lineWebhookServer) start() error {}go func() {if err := s.server.Serve(listener); err != nil && !errors.Is(err, http.ErrServerClosed) {- log.Printf("[line] webhook server exited: %v", err)+ common.Error("line: webhook server exited", err)}}()- log.Printf("[line] webhook listening on http://%s/line/<account_id>/webhook", addr)+ common.Info("line: webhook listening", zap.String("addr", addr))return nil}diff --git a/internal/channels/qqbot.go b/internal/channels/qqbot.goindex 46b0d2721e..1196142563 100644--- a/internal/channels/qqbot.go+++ b/internal/channels/qqbot.go@@ -25,7 +25,6 @@ import ("errors""fmt""io"- "log""net/http""net/url""runtime/debug"@@ -34,8 +33,10 @@ import ("time""github.com/gorilla/websocket"+ "go.uber.org/zap""ragflow/internal/channels/core"+ "ragflow/internal/common")const (@@ -143,7 +144,7 @@ func (c *qqBotChannel) Start(ctx context.Context) error {c.mu.Unlock()close(done)}()- log.Printf("[qqbot:%s] starting gateway client", c.account.AccountID)+ common.Info("qqbot: starting gateway client", zap.String("account_id", c.account.AccountID))return nil}@@ -210,7 +211,7 @@ func (c *qqBotChannel) run(ctx context.Context) {}}if err != nil && ctx.Err() == nil {- log.Printf("[qqbot:%s] gateway loop error: %v", c.account.AccountID, err)+ common.Error("qqbot: gateway loop error", err, zap.String("account_id", c.account.AccountID))}if !waitForContext(ctx, qqBotReconnectDelay) {return@@ -224,7 +225,7 @@ func (c *qqBotChannel) runGatewaySession(ctx context.Context, gatewayURL string,return err}defer conn.Close()- log.Printf("[qqbot:%s] connected to gateway", c.account.AccountID)+ common.Info("qqbot: connected to gateway", zap.String("account_id", c.account.AccountID))sessionCtx, cancel := context.WithCancel(ctx)defer cancel()@@ -247,7 +248,7 @@ func (c *qqBotChannel) runGatewaySession(ctx context.Context, gatewayURL string,}var payload qqBotGatewayPayloadif err := json.Unmarshal(data, &payload); err != nil {- log.Printf("[qqbot:%s] invalid gateway payload: %.200s", c.account.AccountID, data)+ common.Warn("qqbot: invalid gateway payload", zap.String("account_id", c.account.AccountID), zap.String("payload", fmt.Sprintf("%.200s", data)))continue}if payload.Sequence != nil {@@ -285,7 +286,7 @@ func (c *qqBotChannel) runGatewaySession(ctx context.Context, gatewayURL string,return fmt.Errorf("invalid gateway session (can_resume=%t)", canResume)case 0:if err := c.handleDispatch(ctx, payload.Type, payload.Data); err != nil {- log.Printf("[qqbot:%s] ignored invalid %s event: %v", c.account.AccountID, payload.Type, err)+ common.Warn("qqbot: ignored invalid event", zap.String("account_id", c.account.AccountID), zap.String("event_type", payload.Type), zap.Error(err))}}}@@ -306,7 +307,7 @@ func (c *qqBotChannel) runHeartbeat(ctx context.Context, conn *websocket.Conn, icase <-ticker.C:payload := map[string]any{"op": 1, "d": c.currentSequence()}if err := c.writeJSON(conn, payload); err != nil {- log.Printf("[qqbot:%s] heartbeat failed: %v", c.account.AccountID, err)+ common.Error("qqbot: heartbeat failed", err, zap.String("account_id", c.account.AccountID))_ = conn.Close()return}@@ -369,11 +370,11 @@ func (c *qqBotChannel) handleDispatch(ctx context.Context, eventType string, datgo func() {defer func() {if r := recover(); r != nil {- log.Printf("[qqbot:%s] handler panic: %v\n%s", c.account.AccountID, r, debug.Stack())+ common.Error("qqbot: handler panic", fmt.Errorf("panic: %v", r), zap.String("account_id", c.account.AccountID), zap.String("stack", string(debug.Stack())))}}()if err := handler(ctx, *incoming); err != nil {- log.Printf("[qqbot:%s] handler error: %v", c.account.AccountID, err)+ common.Error("qqbot: handler error", err, zap.String("account_id", c.account.AccountID))}}()}diff --git a/internal/channels/telegram.go b/internal/channels/telegram.goindex b40e485319..233c2afd92 100644--- a/internal/channels/telegram.go+++ b/internal/channels/telegram.go@@ -22,7 +22,6 @@ import ("encoding/json""fmt""io"- "log""net/http""net/url""strconv"@@ -30,7 +29,10 @@ import ("sync""time"+ "go.uber.org/zap"+"ragflow/internal/channels/core"+ "ragflow/internal/common")const (@@ -201,7 +203,7 @@ func (c *telegramChannel) Stop(ctx context.Context) error {func (c *telegramChannel) Send(ctx context.Context, msg core.OutgoingMessage) error {chatID, err := strconv.ParseInt(strings.TrimSpace(msg.ChatID), 10, 64)if err != nil {- log.Printf("[telegram:%s] invalid chat_id %q: %v", c.account.AccountID, msg.ChatID, err)+ common.Warn("telegram: invalid chat_id", zap.String("account_id", c.account.AccountID), zap.String("chat_id", msg.ChatID), zap.Error(err))return nil}@@ -218,7 +220,7 @@ func (c *telegramChannel) Send(ctx context.Context, msg core.OutgoingMessage) er}}if err := c.callAPI(ctx, "sendMessage", payload, nil); err != nil {- log.Printf("[telegram:%s] send failed: %v", c.account.AccountID, err)+ common.Error("telegram: send failed", err, zap.String("account_id", c.account.AccountID))}return nil}@@ -232,7 +234,7 @@ func (c *telegramChannel) run(ctx context.Context) {if err == nil {break}- log.Printf("[telegram:%s] failed to start polling: %v", c.account.AccountID, err)+ common.Error("telegram: failed to start polling", err, zap.String("account_id", c.account.AccountID))if !waitForTelegramRetry(ctx) {return}@@ -247,7 +249,7 @@ func (c *telegramChannel) run(ctx context.Context) {if ctx.Err() != nil {return}- log.Printf("[telegram:%s] polling failed: %v", c.account.AccountID, err)+ common.Error("telegram: polling failed", err, zap.String("account_id", c.account.AccountID))if !waitForTelegramRetry(ctx) {return}@@ -277,7 +279,7 @@ func (c *telegramChannel) getUpdates(ctx context.Context) ([]telegramUpdate, errfor _, raw := range rawUpdates {var update telegramUpdateif err := json.Unmarshal(raw, &update); err != nil {- log.Printf("[telegram:%s] ignored invalid update: %v", c.account.AccountID, err)+ common.Warn("telegram: ignored invalid update", zap.String("account_id", c.account.AccountID), zap.Error(err))continue}_ = json.Unmarshal(raw, &update.Raw)@@ -326,7 +328,7 @@ func (c *telegramChannel) handleUpdate(ctx context.Context, update telegramUpdatreturn}if err := handler(ctx, incoming); err != nil {- log.Printf("[telegram:%s] message handler error: %v", c.account.AccountID, err)+ common.Error("telegram: message handler error", err, zap.String("account_id", c.account.AccountID))}}diff --git a/internal/channels/wecom.go b/internal/channels/wecom.goindex 678c62a6c3..d241254b5b 100644--- a/internal/channels/wecom.go+++ b/internal/channels/wecom.go@@ -23,7 +23,6 @@ import ("errors""fmt""io"- "log""net/http""net/url""strconv"@@ -33,8 +32,10 @@ import ("time""github.com/gorilla/websocket"+ "go.uber.org/zap""ragflow/internal/channels/core"+ "ragflow/internal/common")const (@@ -249,7 +250,7 @@ func (c *wecomChannel) Start(ctx context.Context) error {c.mu.Lock()c.server = serverc.mu.Unlock()- log.Printf("[wecom:%s] registered webhook at /wecom/%s/callback", c.account.AccountID, c.account.AccountID)+ common.Info("wecom: registered webhook", zap.String("account_id", c.account.AccountID))return nil}@@ -317,12 +318,12 @@ func (c *wecomChannel) Stop(ctx context.Context) error {func (c *wecomChannel) Send(ctx context.Context, msg core.OutgoingMessage) error {if c.account.ConnectionType == "websocket" {if err := c.sendWebSocketMessage(msg); err != nil {- log.Printf("[wecom:%s] websocket send failed: %v", c.account.AccountID, err)+ common.Error("wecom: websocket send failed", err, zap.String("account_id", c.account.AccountID))}return nil}if err := c.sendApplicationMessage(ctx, msg); err != nil {- log.Printf("[wecom:%s] application send failed: %v", c.account.AccountID, err)+ common.Error("wecom: application send failed", redactURLError(err), zap.String("account_id", c.account.AccountID))}return nil}@@ -334,11 +335,11 @@ func (c *wecomChannel) runWebSocket(ctx context.Context) {return}if errors.Is(err, errWeComAuthentication) || errors.Is(err, errWeComDisconnected) {- log.Printf("[wecom:%s] websocket stopped: %v", c.account.AccountID, err)+ common.Error("wecom: websocket stopped", err, zap.String("account_id", c.account.AccountID))return}if err != nil {- log.Printf("[wecom:%s] websocket loop error: %v", c.account.AccountID, err)+ common.Error("wecom: websocket loop error", err, zap.String("account_id", c.account.AccountID))}if !waitForWeComRetry(ctx) {return@@ -393,7 +394,7 @@ func (c *wecomChannel) runWebSocketOnce(ctx context.Context) error {}disconnect, err := c.handleWebSocketPayload(ctx, payload)if err != nil {- log.Printf("[wecom:%s] invalid websocket payload: %v", c.account.AccountID, err)+ common.Warn("wecom: invalid websocket payload", zap.String("account_id", c.account.AccountID), zap.Error(err))continue}if disconnect {@@ -422,7 +423,7 @@ func (c *wecomChannel) subscribeWebSocket(conn *websocket.Conn) error {return fmt.Errorf("WeCom websocket subscribe acknowledgement: %w", err)}if cmd := weComRawStringValue(response["cmd"]); cmd != "aibot_subscribe" {- log.Printf("[wecom:%s] unexpected subscribe response command %q", c.account.AccountID, cmd)+ common.Warn("wecom: unexpected subscribe response command", zap.String("account_id", c.account.AccountID), zap.String("cmd", cmd))}errCode := weComIntValue(response["errcode"])if errCode == 853000 {@@ -431,7 +432,7 @@ func (c *wecomChannel) subscribeWebSocket(conn *websocket.Conn) error {if errCode != 0 {return fmt.Errorf("WeCom websocket subscribe failed: errcode=%d errmsg=%s", errCode, weComStringValue(response["errmsg"]))}- log.Printf("[wecom:%s] websocket subscribed", c.account.AccountID)+ common.Info("wecom: websocket subscribed", zap.String("account_id", c.account.AccountID))return nil}@@ -473,7 +474,7 @@ func (c *wecomChannel) handleWebSocketPayload(ctx context.Context, payload []byt}case "aibot_subscribe", "aibot_respond_msg", "aibot_respond_welcome_msg", "aibot_send_msg", "ping":if code := weComIntValue(object["errcode"]); code != 0 {- log.Printf("[wecom:%s] websocket response error: %s", c.account.AccountID, string(payload))+ common.Warn("wecom: websocket response error", zap.String("account_id", c.account.AccountID), zap.String("payload", string(payload)))}}return false, nil@@ -645,6 +646,22 @@ func (c *wecomChannel) requestJSON(ctx context.Context, method, endpoint string,return nil}+// redactURLError strips the query string from transport errors. WeCom carries+// the access token / corp secret in the request URL query, and *url.Error keeps+// the full URL in its message, so raw errors must not reach the log sinks.+func redactURLError(err error) error {+ var urlErr *url.Error+ if !errors.As(err, &urlErr) {+ return err+ }+ parsed, parseErr := url.Parse(urlErr.URL)+ if parseErr != nil {+ return urlErr+ }+ parsed.RawQuery = ""+ return &url.Error{Op: urlErr.Op, URL: parsed.String(), Err: urlErr.Err}+}+func (c *wecomChannel) handleTextMessage(ctx context.Context, chatID, senderID, messageID, text, chatType string, raw map[string]any) {if strings.TrimSpace(text) == "" {return@@ -665,7 +682,7 @@ func (c *wecomChannel) handleTextMessage(ctx context.Context, chatID, senderID,Text: text,Raw: raw,}); err != nil {- log.Printf("[wecom:%s] message handler error: %v", c.account.AccountID, err)+ common.Error("wecom: message handler error", err, zap.String("account_id", c.account.AccountID))}}diff --git a/internal/channels/wecom_webhook.go b/internal/channels/wecom_webhook.goindex 76d61e66af..b574c709f1 100644--- a/internal/channels/wecom_webhook.go+++ b/internal/channels/wecom_webhook.go@@ -29,7 +29,6 @@ import ("errors""fmt""io"- "log""net""net/http""net/url"@@ -38,6 +37,10 @@ import ("strings""sync""time"++ "go.uber.org/zap"++ "ragflow/internal/common")const (@@ -205,10 +208,10 @@ func acquireWeComWebhookServer(channel *wecomChannel) (*wecomWebhookServer, errogo func() {if err := server.server.Serve(listener); err != nil && !errors.Is(err, http.ErrServerClosed) {- log.Printf("[wecom] webhook server %s stopped: %v", listener.Addr(), err)+ common.Error("wecom: webhook server stopped", err, zap.String("addr", listener.Addr().String()))}}()- log.Printf("[wecom] webhook listening on http://%s/wecom/<account_id>/callback", listener.Addr())+ common.Info("wecom: webhook listening", zap.String("addr", listener.Addr().String()))return server, nil}@@ -270,13 +273,13 @@ func (s *wecomWebhookServer) handleRequest(w http.ResponseWriter, r *http.Requesbody, err := io.ReadAll(io.LimitReader(r.Body, weComWebhookBodyLimit))if err != nil {- log.Printf("[wecom:%s] failed to read request body: %v", accountID, err)+ common.Warn("wecom: failed to read request body", zap.String("account_id", accountID), zap.Error(err))w.WriteHeader(http.StatusOK)return}var envelope wecomEncryptedXMLif err := xml.Unmarshal(body, &envelope); err != nil || strings.TrimSpace(envelope.Encrypt) == "" {- log.Printf("[wecom:%s] invalid encrypted message: %v", accountID, err)+ common.Warn("wecom: invalid encrypted message", zap.String("account_id", accountID), zap.Error(err))w.WriteHeader(http.StatusOK)return}@@ -287,7 +290,7 @@ func (s *wecomWebhookServer) handleRequest(w http.ResponseWriter, r *http.Reques}var message wecomXMLMessageif err := xml.Unmarshal(plaintext, &message); err != nil {- log.Printf("[wecom:%s] failed to parse decrypted message: %v", accountID, err)+ common.Warn("wecom: failed to parse decrypted message", zap.String("account_id", accountID), zap.Error(err))w.WriteHeader(http.StatusOK)return}diff --git a/internal/channels/whatsapp.go b/internal/channels/whatsapp.goindex f87c87788a..c501893317 100644--- a/internal/channels/whatsapp.go+++ b/internal/channels/whatsapp.go@@ -23,7 +23,6 @@ import ("errors""fmt""io"- "log""net/http""net/url""strconv"@@ -32,8 +31,10 @@ import ("time""github.com/gorilla/websocket"+ "go.uber.org/zap""ragflow/internal/channels/core"+ "ragflow/internal/common")const (@@ -268,7 +269,7 @@ func (c *whatsappChannel) run(ctx context.Context) {for ctx.Err() == nil {if err := c.runEvents(ctx); err != nil && ctx.Err() == nil {c.setError(err)- log.Printf("[whatsapp:%s] event loop error: %v", c.account.AccountID, err)+ common.Error("whatsapp: event loop error", err, zap.String("account_id", c.account.AccountID))time.Sleep(defaultReconnect)}}@@ -285,7 +286,7 @@ func (c *whatsappChannel) startSession(ctx context.Context) error {return c.waitForStatus(ctx)}if statusErr := c.waitForStatus(ctx); statusErr == nil {- log.Printf("[whatsapp:%s] start request returned error after gateway created the session: %v", c.account.AccountID, err)+ common.Warn("whatsapp: start request returned error after gateway created the session", zap.String("account_id", c.account.AccountID), zap.Error(err))return nil}return err@@ -452,7 +453,7 @@ func (c *whatsappChannel) enqueueIncoming(ctx context.Context, incoming core.Incgo c.runChatWorker(ctx, incoming.ChatID, worker)}if queueFull {- log.Printf("[whatsapp:%s] dropping message %s for chat %s: queue is full", c.account.AccountID, incoming.MessageID, incoming.ChatID)+ common.Warn("whatsapp: dropping message, queue is full", zap.String("account_id", c.account.AccountID), zap.String("message_id", incoming.MessageID), zap.String("chat_id", incoming.ChatID))}return false}@@ -506,7 +507,7 @@ func (c *whatsappChannel) handleIncoming(ctx context.Context, incoming core.Incoreturn}if err := handler(ctx, incoming); err != nil {- log.Printf("[whatsapp:%s] message handler error: %v", c.account.AccountID, err)+ common.Error("whatsapp: message handler error", err, zap.String("account_id", c.account.AccountID))}}diff --git a/internal/channels/whatsapp_gateway.go b/internal/channels/whatsapp_gateway.goindex a359051191..c20fd92990 100644--- a/internal/channels/whatsapp_gateway.go+++ b/internal/channels/whatsapp_gateway.go@@ -20,7 +20,6 @@ import ("context""errors""fmt"- "log""net/http""os""os/exec"@@ -30,6 +29,8 @@ import ("strings""sync""time"++ "ragflow/internal/common")const (@@ -149,7 +150,7 @@ func (r *gatewayRuntime) start(ctx context.Context) error {}r.mu.Unlock()if err != nil && owned {- log.Printf("whatsapp gateway exited: %v", err)+ common.Error("whatsapp gateway exited", err)}}()if err := waitForGateway(ctx, gatewayStartTimeout); err != nil {diff --git a/internal/common/time.go b/internal/common/time.goindex f872d48f73..75fa48df31 100644--- a/internal/common/time.go+++ b/internal/common/time.go@@ -17,9 +17,10 @@package commonimport (- "log/slog""strings""time"++ "go.uber.org/zap")// ParseISO8601 parses a date string trying multiple ISO 8601 / RFC3339@@ -76,7 +77,7 @@ func ParseISO8601(dateString string) (time.Time, error) {func FormatISO8601ToYMDHMS(timeStr string) string {dt, err := ParseISO8601(timeStr)if err != nil {- slog.Error("FormatISO8601ToYMDHMS parse error", "input", timeStr, "error", err)+ Error("FormatISO8601ToYMDHMS parse error", err, zap.String("input", timeStr))return timeStr}return dt.Format("2006-01-02 15:04:05")diff --git a/internal/dao/file.go b/internal/dao/file.goindex ddbb75b1e7..0c5113eb84 100644--- a/internal/dao/file.go+++ b/internal/dao/file.go@@ -19,11 +19,12 @@ package daoimport ("context""fmt"- "log"+ "ragflow/internal/common""ragflow/internal/entity""ragflow/internal/utility""strings"+ "go.uber.org/zap""gorm.io/gorm")@@ -475,12 +476,12 @@ func (dao *FileDAO) InitDatasetDocs(ctx context.Context, db *gorm.DB, rootID, teif len(existing) > 0 {if len(existing) > 1 {- log.Printf("[WARN] Found %d duplicate '%s' folders under root %s, keeping only the first",- len(existing), DatasetFolderName, rootID)+ common.Warn("Found duplicate folders under root, keeping only the first",+ zap.Int("duplicates", len(existing)), zap.String("name", DatasetFolderName), zap.String("root_id", rootID))keepID := existing[0].IDfor _, dup := range existing[1:] {if err := reparentAndDeleteFolder(ctx, db, dup.ID, keepID); err != nil {- log.Printf("[ERROR] Failed to deduplicate folder %s: %v", dup.ID, err)+ common.Error("Failed to deduplicate folder", err, zap.String("folder_id", dup.ID))}}}@@ -534,12 +535,12 @@ func (dao *FileDAO) newAFileFromDataset(ctx context.Context, db *gorm.DB, tenantif len(existingFiles) > 0 {if len(existingFiles) > 1 {- log.Printf("[WARN] Found %d duplicate entries named '%s' under parent %s, keeping only the first",- len(existingFiles), name, parentID)+ common.Warn("Found duplicate entries under parent, keeping only the first",+ zap.Int("duplicates", len(existingFiles)), zap.String("name", name), zap.String("parent_id", parentID))keepID := existingFiles[0].IDfor _, dup := range existingFiles[1:] {if err = reparentAndDeleteFolder(ctx, db, dup.ID, keepID); err != nil {- log.Printf("[ERROR] Failed to deduplicate file entry %s: %v", dup.ID, err)+ common.Error("Failed to deduplicate file entry", err, zap.String("entry_id", dup.ID))}}}diff --git a/internal/deepdoc/parser/pdf/batch_smoke_test.go b/internal/deepdoc/parser/pdf/batch_smoke_test.goindex 6d86df8aca..fd7f7bf772 100644--- a/internal/deepdoc/parser/pdf/batch_smoke_test.go+++ b/internal/deepdoc/parser/pdf/batch_smoke_test.go@@ -6,7 +6,6 @@ import ("context""encoding/json""fmt"- "log/slog""math""os""path/filepath"@@ -39,7 +38,7 @@ import (//// For read-only comparison, see compare_test.go (no CGO needed).func TestBatchResults(t *testing.T) {- setupLogger()+ setupLogger(t)pdfDir := filepath.Join("testdata", "real_pdfs")all := listRealPDFs(t, pdfDir)@@ -64,15 +63,16 @@ func TestBatchResults(t *testing.T) {// ── helpers ─────────────────────────────────────────────────────────-func setupLogger() {- level := slog.LevelInfo+func setupLogger(t *testing.T) {+ restoreLoggerGlobals(t)+ level := "info"switch common.GetEnv(common.EnvBatchLogLevel) {case "debug":- level = slog.LevelDebug+ level = "debug"case "warn":- level = slog.LevelWarn+ level = "warn"}- slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: level})))+ _ = common.InitLogger(level, common.FileOutput{}, "")}type outputDirs struct {diff --git a/internal/deepdoc/parser/pdf/compare_test.go b/internal/deepdoc/parser/pdf/compare_test.goindex 1a15a728c0..dd339ac61e 100644--- a/internal/deepdoc/parser/pdf/compare_test.go+++ b/internal/deepdoc/parser/pdf/compare_test.go@@ -3,12 +3,11 @@package pdfimport (- "log/slog"- "os""path/filepath"- "ragflow/internal/common""testing"+ "ragflow/internal/common"+"ragflow/internal/deepdoc/parser/pdf/tool")@@ -17,14 +16,17 @@ import (// no generation, no CGO/DeepDoc dependency. Use PY_OCR_SUFFIX to override// the Python variant.func TestBatchCompareWithPython(t *testing.T) {- level := slog.LevelInfo- if common.GetEnv(common.EnvBatchLogLevel) == "debug" {- level = slog.LevelDebug+ restoreLoggerGlobals(t)+ level := "info"+ switch common.GetEnv(common.EnvBatchLogLevel) {+ case "debug":+ level = "debug"+ case "warn":+ level = "warn"}- if common.GetEnv(common.EnvBatchLogLevel) == "warn" {- level = slog.LevelWarn+ if err := common.InitLogger(level, common.FileOutput{}, ""); err != nil {+ t.Fatalf("init logger: %v", err)}- slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: level})))goVariant := "ocr"pyVariant := common.GetEnv(common.EnvPYOCRSuffix)diff --git a/internal/deepdoc/parser/pdf/layout/layout.go b/internal/deepdoc/parser/pdf/layout/layout.goindex 00bb4ec8cc..1916f52350 100644--- a/internal/deepdoc/parser/pdf/layout/layout.go+++ b/internal/deepdoc/parser/pdf/layout/layout.go@@ -1,16 +1,19 @@package layoutimport (- "log/slog""math"- pdf "ragflow/internal/deepdoc/parser/pdf/type"- util "ragflow/internal/deepdoc/parser/pdf/util""regexp""slices""sort""strings""unicode""unicode/utf8"++ "go.uber.org/zap"++ "ragflow/internal/common"+ pdf "ragflow/internal/deepdoc/parser/pdf/type"+ util "ragflow/internal/deepdoc/parser/pdf/util")// ---- Column assignment ----@@ -472,7 +475,7 @@ func NaiveVerticalMerge(boxes []pdf.TextBox, medianHeights map[int]float64, mediprocessed := processPageBoxes(bxs, mh, mw, pageEnglish[pg])result = append(result, processed...)}- slog.Debug("vm result", "in", len(boxes), "out", len(result))+ common.Debug("vm result", zap.Int("in", len(boxes)), zap.Int("out", len(result)))return result}@@ -528,21 +531,24 @@ func groupBoxesByPage(boxes []pdf.TextBox) (map[int][]int, []int) {func shouldMergeBoxes(prev, curr *pdf.TextBox, mh, mw float64, isEnglish bool) bool {// Check layout numberif prev.LayoutNo != curr.LayoutNo {- slog.Debug("vm reject", "reason", "layoutNo", "prevLayout", prev.LayoutNo, "currLayout", curr.LayoutNo)+ common.Debug("vm reject", zap.String("reason", "layoutNo"),+ zap.String("prevLayout", prev.LayoutNo), zap.String("currLayout", curr.LayoutNo))return false}// Check vertical gapgap := curr.Top - prev.Bottomif gap > mh*1.5 {- slog.Debug("vm reject", "reason", "gap", "gap", gap, "threshold", mh*1.5, "mh", mh)+ common.Debug("vm reject", zap.String("reason", "gap"),+ zap.Float64("gap", gap), zap.Float64("threshold", mh*1.5), zap.Float64("mh", mh))return false}// Check horizontal overlapov := util.OverlapX(prev, curr)if ov < 0.3 {- slog.Debug("vm reject", "reason", "ovX", "ov", ov, "threshold", 0.3)+ common.Debug("vm reject", zap.String("reason", "ovX"),+ zap.Float64("ov", ov), zap.Float64("threshold", 0.3))return false}@@ -586,7 +592,7 @@ func mergeTwoBoxes(prev, curr pdf.TextBox) pdf.TextBox {if r := []rune(currTrunc); len(r) > 40 {currTrunc = string(r[:40])}- slog.Debug("vm merge", "prev", prevTrunc, "curr", currTrunc)+ common.Debug("vm merge", zap.String("prev", prevTrunc), zap.String("curr", currTrunc))return prev}diff --git a/internal/deepdoc/parser/pdf/layout/toc_header_footer.go b/internal/deepdoc/parser/pdf/layout/toc_header_footer.goindex 62ebefbb31..d68b312935 100644--- a/internal/deepdoc/parser/pdf/layout/toc_header_footer.go+++ b/internal/deepdoc/parser/pdf/layout/toc_header_footer.go@@ -1,12 +1,14 @@package layoutimport (- "log/slog""regexp""sort""strings""unicode/utf8"+ "go.uber.org/zap"++ "ragflow/internal/common"pdf "ragflow/internal/deepdoc/parser/pdf/type")@@ -555,13 +557,17 @@ func RemoveHeaderFooterBoxes(boxes []pdf.TextBox, pageHeights map[int]float64) [lt := strings.TrimSpace(b.LayoutType)if (zone == "header" && lt == "header") || (zone == "footer" && lt == "footer") {- slog.Debug("header_footer: dropped by DLA label", "page", b.PageNumber, "zone", zone, "layoutType", lt, "textLen", utf8.RuneCountInString(b.Text))+ common.Debug("header_footer: dropped by DLA label",+ zap.Int("page", b.PageNumber), zap.String("zone", zone),+ zap.String("layoutType", lt), zap.Int("textLen", utf8.RuneCountInString(b.Text)))drop[i] = struct{}{}continue}if isDeterministicPageNumber(b.Text, zone, allGapAbove[i], allGapBelow[i], numPages) {- slog.Debug("header_footer: dropped by page-number pattern", "page", b.PageNumber, "zone", zone, "textLen", utf8.RuneCountInString(b.Text))+ common.Debug("header_footer: dropped by page-number pattern",+ zap.Int("page", b.PageNumber), zap.String("zone", zone),+ zap.Int("textLen", utf8.RuneCountInString(b.Text)))drop[i] = struct{}{}continue}@@ -571,7 +577,8 @@ func RemoveHeaderFooterBoxes(boxes []pdf.TextBox, pageHeights map[int]float64) [if len(drop) == 0 {return boxes}- slog.Debug("header_footer: removal completed (short document)", "total_boxes", len(boxes), "dropped_boxes", len(drop))+ common.Debug("header_footer: removal completed (short document)",+ zap.Int("total_boxes", len(boxes)), zap.Int("dropped_boxes", len(drop)))return applyDrop(boxes, drop)}@@ -644,7 +651,9 @@ func RemoveHeaderFooterBoxes(boxes []pdf.TextBox, pageHeights map[int]float64) [}if reason != "" {- slog.Debug("header_footer: dropped by recurrence", "zone", key.zone, "textLen", utf8.RuneCountInString(key.text), "reason", reason, "pages", distinctPages)+ common.Debug("header_footer: dropped by recurrence",+ zap.String("zone", key.zone), zap.Int("textLen", utf8.RuneCountInString(key.text)),+ zap.String("reason", reason), zap.Int("pages", distinctPages))for _, m := range metas {drop[m.idx] = struct{}{}}@@ -657,7 +666,9 @@ func RemoveHeaderFooterBoxes(boxes []pdf.TextBox, pageHeights map[int]float64) [if len(metas) >= 3 && utf8.RuneCountInString(key.text) <= 60 {runIndices := findStableConsecutiveRunIndices(metas, 3, 4.0)if len(runIndices) > 0 {- slog.Debug("header_footer: dropped by recurrence", "zone", key.zone, "textLen", utf8.RuneCountInString(key.text), "reason", "local_consecutive_run", "boxes", len(runIndices))+ common.Debug("header_footer: dropped by recurrence",+ zap.String("zone", key.zone), zap.Int("textLen", utf8.RuneCountInString(key.text)),+ zap.String("reason", "local_consecutive_run"), zap.Int("boxes", len(runIndices)))for _, idx := range runIndices {drop[idx] = struct{}{}}@@ -668,7 +679,8 @@ func RemoveHeaderFooterBoxes(boxes []pdf.TextBox, pageHeights map[int]float64) [if len(drop) == 0 {return boxes}- slog.Debug("header_footer: removal completed", "total_boxes", len(boxes), "dropped_boxes", len(drop))+ common.Debug("header_footer: removal completed",+ zap.Int("total_boxes", len(boxes)), zap.Int("dropped_boxes", len(drop)))return applyDrop(boxes, drop)}diff --git a/internal/deepdoc/parser/pdf/logger_reset_test.go b/internal/deepdoc/parser/pdf/logger_reset_test.gonew file mode 100644index 0000000000..57dc186861--- /dev/null+++ b/internal/deepdoc/parser/pdf/logger_reset_test.go@@ -0,0 +1,29 @@+//go:build manual++package pdf++import (+ "testing"++ "ragflow/internal/common"+)++// restoreLoggerGlobals snapshots the process-wide logger state and reinstalls+// it when t completes. common.InitLogger overwrites common.Logger, common.Sugar+// and the shared log level, so a test that calls it would otherwise leak that+// state into later tests in the same manual-tier binary.+func restoreLoggerGlobals(t *testing.T) {+ t.Helper()+ prevLogger, prevSugar := common.Logger, common.Sugar+ var prevLevel string+ if common.Logger != nil {+ prevLevel = common.GetLogLevel()+ }+ t.Cleanup(func() {+ common.Logger = prevLogger+ common.Sugar = prevSugar+ if prevLogger != nil {+ _ = common.SetLogLevel(prevLevel)+ }+ })+}diff --git a/internal/deepdoc/parser/pdf/parser_ocr.go b/internal/deepdoc/parser/pdf/parser_ocr.goindex b44d25c344..0e765691a1 100644--- a/internal/deepdoc/parser/pdf/parser_ocr.go+++ b/internal/deepdoc/parser/pdf/parser_ocr.go@@ -3,13 +3,16 @@ package pdfimport ("context""image"- "log/slog""math"+ "sort"+ "strings"++ "go.uber.org/zap"++ "ragflow/internal/common"lyt "ragflow/internal/deepdoc/parser/pdf/layout"pdf "ragflow/internal/deepdoc/parser/pdf/type"util "ragflow/internal/deepdoc/parser/pdf/util"- "sort"- "strings")func (p *Parser) ocrDetectAndRecognize(ctx context.Context, pageImg image.Image, doc pdf.DocAnalyzer, pageNum int, logLabel string, zoom float64) []pdf.TextBox {@@ -116,7 +119,8 @@ func (p *Parser) ocrDetectAndRecognize(ctx context.Context, pageImg image.Image,// Defensive: a count mismatch (or a nil result) would corrupt the// per-box indexing further down. Fall back to per-crop instead of// indexing out of range.- slog.Warn(logLabel+" OCR batch recognize returned unexpected count; falling back to per-crop", "page", pageNum, "got", len(batch), "want", len(cropAcc))+ common.Warn(logLabel+" OCR batch recognize returned unexpected count; falling back to per-crop",+ zap.Int("page", pageNum), zap.Int("got", len(batch)), zap.Int("want", len(cropAcc)))default:allTexts = batch}@@ -260,7 +264,7 @@ func (p *Parser) detectBoxes(ctx context.Context, pageImg image.Image, doc pdf.Dif err != nil || len(ocrDetectBoxes) == 0 {return nil, 0, err}- slog.Debug("ocrMergeChars detect", "page", pageNum, "boxes", len(ocrDetectBoxes))+ common.Debug("ocrMergeChars detect", zap.Int("page", pageNum), zap.Int("boxes", len(ocrDetectBoxes)))// The caller multiplies the returned boxes back by this scale to crop the// original render, so passing the render zoom keeps the round trip exact@@ -625,6 +629,6 @@ func (p *Parser) buildTextBoxes(ctx context.Context, pageImg image.Image,filtered = append(filtered, tb)}}- slog.Debug("ocrMergeChars result", "page", pageNum, "boxes", len(filtered))+ common.Debug("ocrMergeChars result", zap.Int("page", pageNum), zap.Int("boxes", len(filtered)))return filtered}diff --git a/internal/deepdoc/parser/pdf/table/table_cells.go b/internal/deepdoc/parser/pdf/table/table_cells.goindex 3057a680ef..84c00f4ecf 100644--- a/internal/deepdoc/parser/pdf/table/table_cells.go+++ b/internal/deepdoc/parser/pdf/table/table_cells.go@@ -1,12 +1,14 @@package tableimport (- "log/slog""math""regexp""sort""strings"+ "go.uber.org/zap"++ "ragflow/internal/common"pdf "ragflow/internal/deepdoc/parser/pdf/type""ragflow/internal/deepdoc/parser/pdf/util")@@ -121,7 +123,7 @@ func FillCellTextFromBoxes(cells []pdf.TSRCell, boxes []pdf.TextBox) {// every data row regardless of whether the table has a header. Rows with no// matching TSR row component (e.g. header rows) keep the grid-union strip X.func FillCellTextFromBoxesWithRows(cells []pdf.TSRCell, boxes []pdf.TextBox, rowStrips []pdf.TSRCell) {- slog.Debug("fillCellTextFromBoxes", "cells", len(cells), "boxes", len(boxes))+ common.Debug("fillCellTextFromBoxes", zap.Int("cells", len(cells)), zap.Int("boxes", len(boxes)))if len(cells) == 0 || len(boxes) == 0 {return}@@ -349,7 +351,7 @@ func FillCellTextFromBoxesWithRows(cells []pdf.TSRCell, boxes []pdf.TextBox, rowcells[i].Text = cellText[i]}}- slog.Debug("fillCellTextFromBoxes done", "box_cell_matches", matched, "cells_filled", matched)+ common.Debug("fillCellTextFromBoxes done", zap.Int("box_cell_matches", matched), zap.Int("cells_filled", matched))}// tightestColumnDistance mirrors Python's find_horizontally_tightest_fitdiff --git a/internal/deepdoc/parser/pdf/table/table_orient.go b/internal/deepdoc/parser/pdf/table/table_orient.goindex cd86f69387..ba73101b80 100644--- a/internal/deepdoc/parser/pdf/table/table_orient.go+++ b/internal/deepdoc/parser/pdf/table/table_orient.go@@ -4,9 +4,11 @@ import ("context""fmt""image"- "log/slog""math"+ "go.uber.org/zap"++ "ragflow/internal/common"pdf "ragflow/internal/deepdoc/parser/pdf/type""ragflow/internal/deepdoc/parser/pdf/util")@@ -59,7 +61,7 @@ func EvaluateTableOrientation(ctx context.Context, tableImg image.Image, doc pdfif rot.angle != 0 {rotated = util.RotateImageCW(tableImg, rot.angle)if rotated == nil {- slog.Warn("table rotate failed", "angle", rot.angle)+ common.Warn("table rotate failed", zap.Int("angle", rot.angle))continue}}@@ -110,11 +112,11 @@ func EvaluateTableOrientation(ctx context.Context, tableImg image.Image, doc pdfcombined := avgConf * (1 + 0.1*math.Min(float64(regions), 50)/50)scores[rot.angle] = combined- slog.Debug("table orientation",- "angle", rot.angle,- "regions", regions,- "avg_conf", fmt.Sprintf("%.4f", avgConf),- "combined", fmt.Sprintf("%.4f", combined))+ common.Debug("table orientation",+ zap.Int("angle", rot.angle),+ zap.Int("regions", regions),+ zap.String("avg_conf", fmt.Sprintf("%.4f", avgConf)),+ zap.String("combined", fmt.Sprintf("%.4f", combined)))if combined > bestScore {bestScore = combined@@ -136,9 +138,9 @@ func EvaluateTableOrientation(ctx context.Context, tableImg image.Image, doc pdf}}- slog.Debug("best table orientation",- "angle", bestAngle,- "score", fmt.Sprintf("%.4f", bestScore))+ common.Debug("best table orientation",+ zap.Int("angle", bestAngle),+ zap.String("score", fmt.Sprintf("%.4f", bestScore)))return bestAngle, bestImg, scores}diff --git a/internal/deepdoc/parser/pdf/table/table_post.go b/internal/deepdoc/parser/pdf/table/table_post.goindex 3149a17d99..18fe5ee448 100644--- a/internal/deepdoc/parser/pdf/table/table_post.go+++ b/internal/deepdoc/parser/pdf/table/table_post.go@@ -1,10 +1,12 @@package tableimport (- "log/slog""math""sort"+ "go.uber.org/zap"++ "ragflow/internal/common"pdf "ragflow/internal/deepdoc/parser/pdf/type")@@ -153,7 +155,8 @@ func buildTableHTMLs(boxes []pdf.TextBox, tables []pdf.TableItem) map[int]string}}}- slog.Debug("extractTableAndReplace constructTable", "table", ti, "cells", len(pageGlobalCells), "boxes", len(tableBoxes))+ common.Debug("extractTableAndReplace constructTable",+ zap.Int("table", ti), zap.Int("cells", len(pageGlobalCells)), zap.Int("boxes", len(tableBoxes)))htmls[ti] = ConstructTable(pageGlobalCells, tableBoxes, tables[ti].Caption, &tables[ti])}return htmlsdiff --git a/internal/deepdoc/parser/pdf/table_extract.go b/internal/deepdoc/parser/pdf/table_extract.goindex ebeedd70c2..818c85a4a5 100644--- a/internal/deepdoc/parser/pdf/table_extract.go+++ b/internal/deepdoc/parser/pdf/table_extract.go@@ -3,10 +3,12 @@ package pdfimport ("context""image"- "log/slog""math""strings"+ "go.uber.org/zap"++ "ragflow/internal/common"lyt "ragflow/internal/deepdoc/parser/pdf/layout"tbl "ragflow/internal/deepdoc/parser/pdf/table"pdf "ragflow/internal/deepdoc/parser/pdf/type"@@ -126,7 +128,7 @@ func (p *Parser) processOneTable(ctx context.Context, pageImg image.Image, boxes}imgB64, encErr := util.EncodeImageToBase64PNG(cropped)if encErr != nil {- slog.Warn("table PNG encode failed", "page", pageNum, "err", encErr)+ common.Warn("table PNG encode failed", zap.Int("page", pageNum), zap.Error(encErr))}// Hand the crop origin to TSR so a replay TableBuilder can map Python// page-space TSR cells into this exact crop frame. Production callersdiff --git a/internal/deepdoc/parser/pdf/tool/compare_test.go b/internal/deepdoc/parser/pdf/tool/compare_test.goindex 0754f55021..77e0a7fd47 100644--- a/internal/deepdoc/parser/pdf/tool/compare_test.go+++ b/internal/deepdoc/parser/pdf/tool/compare_test.go@@ -3,8 +3,6 @@package toolimport (- "log/slog"- "os""path/filepath""testing"@@ -16,14 +14,29 @@ import (// no generation, no CGO/DeepDoc dependency. Use PY_OCR_SUFFIX to override// the Python variant.func TestBatchCompareWithPython(t *testing.T) {- level := slog.LevelInfo- if common.GetEnv(common.EnvBatchLogLevel) == "debug" {- level = slog.LevelDebug+ prevLogger, prevSugar := common.Logger, common.Sugar+ var prevLevel string+ if common.Logger != nil {+ prevLevel = common.GetLogLevel()}- if common.GetEnv(common.EnvBatchLogLevel) == "warn" {- level = slog.LevelWarn+ t.Cleanup(func() {+ common.Logger = prevLogger+ common.Sugar = prevSugar+ if prevLogger != nil {+ _ = common.SetLogLevel(prevLevel)+ }+ })++ level := "info"+ switch common.GetEnv(common.EnvBatchLogLevel) {+ case "debug":+ level = "debug"+ case "warn":+ level = "warn"+ }+ if err := common.InitLogger(level, common.FileOutput{}, ""); err != nil {+ t.Fatalf("init logger: %v", err)}- slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: level})))goVariant := "ocr"pyVariant := common.GetEnv(common.EnvPYOCRSuffix)diff --git a/internal/deepdoc/parser/pdf/util/crop.go b/internal/deepdoc/parser/pdf/util/crop.goindex 9f86e3e372..18f030f638 100644--- a/internal/deepdoc/parser/pdf/util/crop.go+++ b/internal/deepdoc/parser/pdf/util/crop.go@@ -5,10 +5,13 @@ import ("fmt""image""image/color"- "log/slog""math"- pdf "ragflow/internal/deepdoc/parser/pdf/type""strings"++ "go.uber.org/zap"++ "ragflow/internal/common"+ pdf "ragflow/internal/deepdoc/parser/pdf/type")// CropSectionImage crops region(s) from rendered page images based on a@@ -18,13 +21,13 @@ import (// Python: pdf_parser.py:1802 RAGFlowPdfParser.crop()func CropSectionImage(posTag string, decodedImages map[int]image.Image, zoom float64) string {if len(decodedImages) == 0 {- slog.Warn("cropSectionImage: no page images available, skipping image generation")+ common.Warn("cropSectionImage: no page images available, skipping image generation")return ""}positions := ExtractPositions(posTag)if len(positions) == 0 {- slog.Warn("cropSectionImage: empty position list in tag", "posTag", posTag[:min(80, len(posTag))])+ common.Warn("cropSectionImage: empty position list in tag", zap.String("posTag", posTag[:min(80, len(posTag))]))return ""}@@ -43,7 +46,7 @@ func CropSectionImage(posTag string, decodedImages map[int]image.Image, zoom flo}}if len(valid) == 0 {- slog.Warn("cropSectionImage: no valid positions after filtering, skipping crop")+ common.Warn("cropSectionImage: no valid positions after filtering, skipping crop")return ""}@@ -143,7 +146,7 @@ func CropSectionImage(posTag string, decodedImages map[int]image.Image, zoom flopageImg, ok := decodedImages[pn0]if !ok {- slog.Warn("cropSectionImage: page image not found", "page", pn0)+ common.Warn("cropSectionImage: page image not found", zap.Int("page", pn0))return ""}pageH := float64(pageImg.Bounds().Dy())@@ -166,7 +169,7 @@ func CropSectionImage(posTag string, decodedImages map[int]image.Image, zoom flo}pageImg2, ok := decodedImages[pn]if !ok {- slog.Warn("cropSectionImage: page image not found for subsequent page", "page", pn)+ common.Warn("cropSectionImage: page image not found for subsequent page", zap.Int("page", pn))return ""}pageH2 := float64(pageImg2.Bounds().Dy())@@ -234,7 +237,7 @@ func CropSectionImage(posTag string, decodedImages map[int]image.Image, zoom flodata, err := EncodePNG(stitched)if err != nil {- slog.Warn("cropSectionImage: PNG encode failed", "err", err)+ common.Warn("cropSectionImage: PNG encode failed", zap.Error(err))return ""}return base64.StdEncoding.EncodeToString(data)@@ -370,8 +373,8 @@ func cropDLAPage(img image.Image, dlaRegions []pdf.DLAPageRegions,if cropped, err := CropImageRegion(img, regions[bestIdx]); err == nil {return cropped} else {- slog.Warn("cropSectionByDLA: cropImageRegion failed, falling back to bbox",- "page", pn, "err", err)+ common.Warn("cropSectionByDLA: cropImageRegion failed, falling back to bbox",+ zap.Int("page", pn), zap.Error(err))}}// Fallback: crop the section bbox on this page (FastCrop clamps to bounds).@@ -432,7 +435,7 @@ func stitchVerticalImages(imgs []image.Image, gap int) string {data, err := EncodePNG(stitched)if err != nil {- slog.Warn("cropSectionByDLA: PNG encode failed", "err", err)+ common.Warn("cropSectionByDLA: PNG encode failed", zap.Error(err))return ""}return base64.StdEncoding.EncodeToString(data)diff --git a/internal/deepdoc/parser/pdf/util/position.go b/internal/deepdoc/parser/pdf/util/position.goindex 380eefaa45..7ffd7f3bfc 100644--- a/internal/deepdoc/parser/pdf/util/position.go+++ b/internal/deepdoc/parser/pdf/util/position.go@@ -2,11 +2,13 @@ package utilimport ("fmt"- "log/slog""regexp""strconv""strings"+ "go.uber.org/zap"++ "ragflow/internal/common"pdf "ragflow/internal/deepdoc/parser/pdf/type")@@ -54,7 +56,8 @@ func ExtractPositions(text string) []pdf.Position {for p := range strings.SplitSeq(parts[0], "-") {n, err := strconv.Atoi(p)if err != nil {- slog.Warn("ExtractPositions: invalid page number in tag", "tag", tag, "part", p, "err", err)+ common.Warn("ExtractPositions: invalid page number in tag",+ zap.String("tag", tag), zap.String("part", p), zap.Error(err))continue}pageNums = append(pageNums, n-1) // 0-index@@ -62,22 +65,22 @@ func ExtractPositions(text string) []pdf.Position {left, err := strconv.ParseFloat(parts[1], 64)if err != nil {- slog.Warn("ExtractPositions: invalid left coordinate", "tag", tag, "err", err)+ common.Warn("ExtractPositions: invalid left coordinate", zap.String("tag", tag), zap.Error(err))continue}right, err := strconv.ParseFloat(parts[2], 64)if err != nil {- slog.Warn("ExtractPositions: invalid right coordinate", "tag", tag, "err", err)+ common.Warn("ExtractPositions: invalid right coordinate", zap.String("tag", tag), zap.Error(err))continue}top, err := strconv.ParseFloat(parts[3], 64)if err != nil {- slog.Warn("ExtractPositions: invalid top coordinate", "tag", tag, "err", err)+ common.Warn("ExtractPositions: invalid top coordinate", zap.String("tag", tag), zap.Error(err))continue}bottom, err := strconv.ParseFloat(parts[4], 64)if err != nil {- slog.Warn("ExtractPositions: invalid bottom coordinate", "tag", tag, "err", err)+ common.Warn("ExtractPositions: invalid bottom coordinate", zap.String("tag", tag), zap.Error(err))continue}diff --git a/internal/entity/flexible_time.go b/internal/entity/flexible_time.goindex e556a4464e..055a5daa0b 100644--- a/internal/entity/flexible_time.go+++ b/internal/entity/flexible_time.go@@ -20,11 +20,14 @@ import ("database/sql/driver""encoding/json""fmt"- "log""net/mail""regexp""strings""time"++ "go.uber.org/zap"++ "ragflow/internal/common")// compactOffsetPattern expands the legacy "+0000" style offsets to "+00:00".@@ -106,7 +109,7 @@ func (f *FlexibleTime) parse(value string) {}}if strings.TrimSpace(original) != "" {- log.Printf("flexible_time: cannot parse %q as time, falling back to zero time", original)+ common.Warn("flexible_time: cannot parse value as time, falling back to zero time", zap.String("value", original))}*f = FlexibleTime{}}diff --git a/internal/common/system_settings.go b/internal/entity/system_settings.gosimilarity index 58%rename from internal/common/system_settings.gorename to internal/entity/system_settings.goindex ba64b929a1..fa47234112 100644--- a/internal/common/system_settings.go+++ b/internal/entity/system_settings.go@@ -1,30 +1,29 @@//-// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.//-// Licensed under the Apache License, Version 2.0 (the "License");-// you may not use this file except in compliance with the License.-// You may obtain a copy of the License at+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at//-// http://www.apache.org/licenses/LICENSE-2.0+// http://www.apache.org/licenses/LICENSE-2.0//-// Unless required by applicable law or agreed to in writing, software-// distributed under the License is distributed on an "AS IS" BASIS,-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.-// See the License for the specific language governing permissions and-// limitations under the License.+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.//-package common+package entityimport ("encoding/json""fmt"- "ragflow/internal/entity""strconv""strings")-func FormatSystemSetting(setting entity.SystemSettings) map[string]interface{} {+func FormatSystemSetting(setting SystemSettings) map[string]interface{} {return map[string]interface{}{"data_type": setting.DataType,"name": setting.Name,@@ -33,7 +32,7 @@ func FormatSystemSetting(setting entity.SystemSettings) map[string]interface{} {}}-func FormatSystemSettings(settings []entity.SystemSettings) []map[string]interface{} {+func FormatSystemSettings(settings []SystemSettings) []map[string]interface{} {result := make([]map[string]interface{}, 0, len(settings))for _, setting := range settings {result = append(result, FormatSystemSetting(setting))@@ -41,7 +40,7 @@ func FormatSystemSettings(settings []entity.SystemSettings) []map[string]interfareturn result}-func ValidateSystemSettingValue(setting entity.SystemSettings, value string) error {+func ValidateSystemSettingValue(setting SystemSettings, value string) error {dataType := strings.ToLower(setting.DataType)switch dataType {case "string":diff --git a/internal/ingestion/component/chunker/general.go b/internal/ingestion/component/chunker/general.goindex 9a7b53cf2a..2f70203ce1 100644--- a/internal/ingestion/component/chunker/general.go+++ b/internal/ingestion/component/chunker/general.go@@ -27,15 +27,16 @@ import (_ "image/gif"_ "image/jpeg""image/png"- "log/slog""path/filepath""regexp""sort""strings"+ "go.uber.org/zap""gorm.io/gorm""ragflow/internal/agent/runtime"+ "ragflow/internal/common""ragflow/internal/ingestion/component/schema""ragflow/internal/parser/chunk")@@ -147,12 +148,13 @@ func (c *GeneralChunkerComponent) Invoke(ctx context.Context, db *gorm.DB, inputif fileType == "" {return nil, fmt.Errorf("GeneralChunker: file_type is required when source name has no extension")}- slog.Warn("GeneralChunker: missing parser file_type; inferred from source name", "name", upstream.Name, "file_type", fileType)+ common.Warn("GeneralChunker: missing parser file_type; inferred from source name",+ zap.String("name", upstream.Name), zap.String("file_type", fileType))}strategy := generalStrategyForFileType(fileType)if strategy == generalStrategyText && !isKnownGeneralFileType(fileType) {- slog.Debug("GeneralChunker: unknown file_type; using text fallback", "file_type", fileType)+ common.Debug("GeneralChunker: unknown file_type; using text fallback", zap.String("file_type", fileType))}switch strategy {@@ -231,7 +233,7 @@ func (c *GeneralChunkerComponent) chunkPDF(ctx context.Context, db *gorm.DB, upsunits = splitGeneralUnits(units, primaryPattern)units = sortPDFUnits(units)if hasPDFPositions(units) && hasUnpositionedPDFMedia(units) {- slog.Warn("GeneralChunker: PDF media is missing position metadata; using degraded context/order fallback")+ common.Warn("GeneralChunker: PDF media is missing position metadata; using degraded context/order fallback")}attachGeneralMediaContext(units, c.param.TableContextSize, c.param.ImageContextSize)@@ -256,7 +258,7 @@ func (c *GeneralChunkerComponent) chunkPDF(ctx context.Context, db *gorm.DB, upsengine, err := newPDFEngineFromUpstream(ctx, db, upstream)if err != nil {- slog.Warn("GeneralChunker: could not open PDF for on-demand cropping", "err", err)+ common.Warn("GeneralChunker: could not open PDF for on-demand cropping", zap.Error(err))}if engine != nil {defer engine.Close()diff --git a/internal/ingestion/component/chunker/general_pdf_fallback_cgo_test.go b/internal/ingestion/component/chunker/general_pdf_fallback_cgo_test.goindex 28d277b7f3..2f88f39770 100644--- a/internal/ingestion/component/chunker/general_pdf_fallback_cgo_test.go+++ b/internal/ingestion/component/chunker/general_pdf_fallback_cgo_test.go@@ -19,10 +19,12 @@ package chunkerimport ("errors"- "log/slog"- "strings""testing"+ "go.uber.org/zap"+ "go.uber.org/zap/zaptest/observer"++ "ragflow/internal/common""ragflow/internal/ingestion/component")@@ -33,10 +35,10 @@ func TestGeneralChunkerPDFContinuesWhenStorageResolutionFails(t *testing.T) {}t.Cleanup(func() { component.ResolveDocumentStorageOverride = previousResolver })- var logs strings.Builder- previousLogger := slog.Default()- slog.SetDefault(slog.New(slog.NewTextHandler(&logs, &slog.HandlerOptions{Level: slog.LevelWarn})))- t.Cleanup(func() { slog.SetDefault(previousLogger) })+ core, logs := observer.New(zap.WarnLevel)+ originalLogger := common.Logger+ common.Logger = zap.New(core)+ t.Cleanup(func() { common.Logger = originalLogger })chunker, err := NewGeneralChunker(nil)if err != nil {@@ -52,8 +54,8 @@ func TestGeneralChunkerPDFContinuesWhenStorageResolutionFails(t *testing.T) {if err != nil {t.Fatalf("GeneralChunker.Invoke: %v", err)}- if !strings.Contains(logs.String(), "could not open PDF") {- t.Fatalf("logs = %q, want PDF open warning", logs.String())+ if logs.FilterMessage("GeneralChunker: could not open PDF for on-demand cropping").Len() != 1 {+ t.Fatalf("logs = %v, want PDF open warning", logs.All())}chunks := outputChunks(t, out)if len(chunks) != 1 || chunks[0]["text"] != "body" {diff --git a/internal/ingestion/component/chunker/general_test.go b/internal/ingestion/component/chunker/general_test.goindex f7ba149f1e..e77939bb7a 100644--- a/internal/ingestion/component/chunker/general_test.go+++ b/internal/ingestion/component/chunker/general_test.go@@ -24,12 +24,14 @@ import ("image""image/color""image/jpeg"- "log/slog""reflect""strings""testing""time"+ "go.uber.org/zap"+ "go.uber.org/zap/zaptest/observer"+"ragflow/internal/agent/runtime""ragflow/internal/common""ragflow/internal/ingestion/component/schema"@@ -164,10 +166,10 @@ func TestGeneralStrategyForFileType(t *testing.T) {}func TestGeneralChunkerLogsUnknownFileTypeFallback(t *testing.T) {- var logs bytes.Buffer- previousLogger := slog.Default()- slog.SetDefault(slog.New(slog.NewTextHandler(&logs, &slog.HandlerOptions{Level: slog.LevelDebug})))- t.Cleanup(func() { slog.SetDefault(previousLogger) })+ core, logs := observer.New(zap.DebugLevel)+ originalLogger := common.Logger+ common.Logger = zap.New(core)+ t.Cleanup(func() { common.Logger = originalLogger })component, err := NewGeneralChunker(nil)if err != nil {@@ -182,11 +184,11 @@ func TestGeneralChunkerLogsUnknownFileTypeFallback(t *testing.T) {if err != nil {t.Fatalf("Invoke unknown file type: %v", err)}- if !strings.Contains(logs.String(), "unknown file_type") {- t.Fatalf("logs = %q, want unknown file_type fallback diagnostic", logs.String())+ if logs.FilterMessage("GeneralChunker: unknown file_type; using text fallback").Len() != 1 {+ t.Fatalf("logs = %v, want unknown file_type fallback diagnostic", logs.All())}- logs.Reset()+ logs.TakeAll()_, err = component.Invoke(t.Context(), nil, map[string]any{"name": "document.txt","file_type": "txt",@@ -196,8 +198,8 @@ func TestGeneralChunkerLogsUnknownFileTypeFallback(t *testing.T) {if err != nil {t.Fatalf("Invoke canonical text file type: %v", err)}- if strings.Contains(logs.String(), "unknown file_type") {- t.Fatalf("canonical text fallback emitted unknown-file diagnostic: %q", logs.String())+ if logs.FilterMessage("GeneralChunker: unknown file_type; using text fallback").Len() != 0 {+ t.Fatalf("canonical text fallback emitted unknown-file diagnostic: %v", logs.All())}}diff --git a/internal/ingestion/component/chunker/group.go b/internal/ingestion/component/chunker/group.goindex 3cab60a8d8..f839bfaee4 100644--- a/internal/ingestion/component/chunker/group.go+++ b/internal/ingestion/component/chunker/group.go@@ -37,7 +37,6 @@ import ("context""encoding/json""fmt"- "log/slog""regexp""sort""strings"@@ -195,7 +194,7 @@ func chunkFromRecords(parentCtx context.Context, db *gorm.DB, inputs map[string]if upstream, uErr := decodeChunkerFromUpstream(inputs); uErr == nil {engine, eErr := newPDFEngineFromUpstream(parentCtx, db, upstream)if eErr != nil {- slog.Warn("chunker: could not open PDF for on-demand cropping", "err", eErr)+ common.Warn("chunker: could not open PDF for on-demand cropping", zap.Error(eErr))}if engine != nil {defer engine.Close()diff --git a/internal/ingestion/component/chunker/hierarchy.go b/internal/ingestion/component/chunker/hierarchy.goindex a7ca007f40..ea59cfc8ce 100644--- a/internal/ingestion/component/chunker/hierarchy.go+++ b/internal/ingestion/component/chunker/hierarchy.go@@ -41,7 +41,6 @@ package chunkerimport ("context""fmt"- "log/slog""go.uber.org/zap""gorm.io/gorm"@@ -260,7 +259,7 @@ func invokeHierarchy(parentCtx context.Context, db *gorm.DB, inputs map[string]aif upstream, uErr := decodeChunkerFromUpstream(inputs); uErr == nil {engine, eErr := newPDFEngineFromUpstream(parentCtx, db, upstream)if eErr != nil {- slog.Warn("HierarchyTitleChunker: could not open PDF for on-demand cropping", "err", eErr)+ common.Warn("HierarchyTitleChunker: could not open PDF for on-demand cropping", zap.Error(eErr))}if engine != nil {defer engine.Close()diff --git a/internal/ingestion/component/chunker/pdfcrop_cgo.go b/internal/ingestion/component/chunker/pdfcrop_cgo.goindex b58f2a7112..90e24e45e8 100644--- a/internal/ingestion/component/chunker/pdfcrop_cgo.go+++ b/internal/ingestion/component/chunker/pdfcrop_cgo.go@@ -14,8 +14,10 @@ import ("context""encoding/json""image"- "log/slog"+ "go.uber.org/zap"++ "ragflow/internal/common"deepdocpdf "ragflow/internal/deepdoc/parser/pdf""ragflow/internal/deepdoc/parser/pdf/util"deepdoctype "ragflow/internal/deepdoc/parser/type"@@ -117,8 +119,8 @@ func cropImageChunks(ctx context.Context, engine deepdoctype.PDFEngine, chunks [}img, rerr := deepdocpdf.RenderPageToImage(engine, pn)if rerr != nil || img == nil {- slog.Warn("cropImageChunks: render failed, skipping page",- "page", pn, "err", rerr)+ common.Warn("cropImageChunks: render failed, skipping page",+ zap.Int("page", pn), zap.Error(rerr))continue}pageCache[pn] = imgdiff --git a/internal/ingestion/component/chunker/token.go b/internal/ingestion/component/chunker/token.goindex 03e33f861b..85e503b6d3 100644--- a/internal/ingestion/component/chunker/token.go+++ b/internal/ingestion/component/chunker/token.go@@ -72,14 +72,15 @@ import ("context""encoding/json""fmt"- "log/slog""regexp""strings""sync""unicode/utf8"+ "go.uber.org/zap""gorm.io/gorm""ragflow/internal/agent/runtime"+ "ragflow/internal/common"deepdoctype "ragflow/internal/deepdoc/parser/type""ragflow/internal/ingestion/component/globals""ragflow/internal/ingestion/component/schema"@@ -233,7 +234,7 @@ func (c *TokenChunkerComponent) invoke(ctx context.Context, db *gorm.DB, inputs// simply skips cropping.engine, engErr := newPDFEngineFromUpstream(ctx, db, upstream)if engErr != nil {- slog.Warn("TokenChunker: could not open PDF for on-demand cropping", "err", engErr)+ common.Warn("TokenChunker: could not open PDF for on-demand cropping", zap.Error(engErr))}if engine != nil {defer engine.Close()diff --git a/internal/ingestion/component/knowledge_compiler/component.go b/internal/ingestion/component/knowledge_compiler/component.goindex 4df8a16c3b..832d40713f 100644--- a/internal/ingestion/component/knowledge_compiler/component.go+++ b/internal/ingestion/component/knowledge_compiler/component.go@@ -7,7 +7,6 @@ package knowledge_compilerimport ("context""fmt"- "log""sort""strings"@@ -800,7 +799,7 @@ func mergeChunks(inputs map[string]any, compiled []schema.ChunkDoc) map[string]araw = append(raw, m)}default:- log.Printf("knowledge_compiler: mergeChunks: unexpected chunks type %T", inputs["chunks"])+ clog.Warn("knowledge_compiler: mergeChunks: unexpected chunks type", zap.String("type", fmt.Sprintf("%T", inputs["chunks"])))}merged := make([]any, 0, len(raw)+len(compiled))for _, r := range raw {@@ -869,9 +868,9 @@ func buildInputs(inputs map[string]any, param common.Param) (common.Inputs, errocase []map[string]any:raw = vdefault:- log.Printf("knowledge_compiler: buildInputs: unexpected chunks type %T", inputs["chunks"])+ clog.Warn("knowledge_compiler: buildInputs: unexpected chunks type", zap.String("type", fmt.Sprintf("%T", inputs["chunks"])))}- log.Printf("knowledge_compiler: buildInputs: accepted %d chunk(s) from inputs[chunks]", len(raw))+ clog.Info("knowledge_compiler: buildInputs: accepted chunks from inputs[chunks]", zap.Int("chunks", len(raw)))for _, m := range raw {ch := common.Chunk{Meta: m}if id, ok := m["id"].(string); ok {diff --git a/internal/ingestion/component/knowledge_compiler/tree/claims.go b/internal/ingestion/component/knowledge_compiler/tree/claims.goindex 7b3f1af061..5706c93c59 100644--- a/internal/ingestion/component/knowledge_compiler/tree/claims.go+++ b/internal/ingestion/component/knowledge_compiler/tree/claims.go@@ -4,13 +4,15 @@ import ("context""encoding/json""fmt"- "log""sort""strings""sync""unicode/utf8"+ "go.uber.org/zap"+"ragflow/internal/agent/runtime"+ rfcommon "ragflow/internal/common""ragflow/internal/ingestion/component/knowledge_compiler/common")@@ -302,13 +304,13 @@ func extractClaimsForBatch(ctx context.Context, deps common.Deps, llmID, claimPr}raw, err := common.GenJSON(ctx, deps.Chat, req)if err != nil {- log.Printf("tree: claim extraction skipped for batch %s: %v", claimBatchLabel(batch), err)+ rfcommon.Warn("tree: claim extraction skipped for batch", zap.String("batch", claimBatchLabel(batch)), zap.Error(err))return nil}items, err := parseClaimItemsMap(raw)if err != nil {- log.Printf("tree: claim extraction skipped for batch %s: %v", claimBatchLabel(batch), err)+ rfcommon.Warn("tree: claim extraction skipped for batch", zap.String("batch", claimBatchLabel(batch)), zap.Error(err))return nil}if len(items) == 0 {@@ -345,8 +347,9 @@ func extractClaimsForBatch(ctx context.Context, deps common.Deps, llmID, claimPr// document would let a quote match an unrelated chunk that merely happens to// contain the same sentence, and would then attribute the claim to it.claims, verified, rejected := ValidateClaims(claims, textByID, mode)- log.Printf("tree: claim extraction batch=%s chunks=%d claims=%d emitted_evidence=%d verified=%d rejected=%d",- claimBatchLabel(batch), len(batch), len(claims), emitted, verified, rejected)+ rfcommon.Info("tree: claim extraction",+ zap.String("batch", claimBatchLabel(batch)), zap.Int("chunks", len(batch)), zap.Int("claims", len(claims)),+ zap.Int("emitted_evidence", emitted), zap.Int("verified", verified), zap.Int("rejected", rejected))// Recover attribution from the evidence that survived the gate: the chunk a// quote was located in IS where the claim came from. A claim that neither the@@ -367,7 +370,7 @@ func extractClaimsForBatch(ctx context.Context, deps common.Deps, llmID, claimPr}}if id == "" {- log.Printf("tree: dropped claim with no attributable source: %s", c.Name)+ rfcommon.Warn("tree: dropped claim with no attributable source", zap.String("claim", c.Name))continue}c.SourceChunkIDs = []string{id}diff --git a/internal/ingestion/component/knowledge_compiler/tree/duplicate_titles.go b/internal/ingestion/component/knowledge_compiler/tree/duplicate_titles.goindex 01d7b9d33e..594f1a9f70 100644--- a/internal/ingestion/component/knowledge_compiler/tree/duplicate_titles.go+++ b/internal/ingestion/component/knowledge_compiler/tree/duplicate_titles.go@@ -4,11 +4,13 @@ import ("context""encoding/json""fmt"- "log""sort""strconv""strings"+ "go.uber.org/zap"++ rfcommon "ragflow/internal/common""ragflow/internal/ingestion/component/knowledge_compiler/common")@@ -65,7 +67,7 @@ func rewriteDuplicateTreeNames(ctx context.Context, deps common.Deps, llmID stricontinue}if err := rewriteTitleGroup(ctx, deps, llmID, title, products, idxs); err != nil {- log.Printf("tree: duplicate title rewrite failed for title=%q (keeping titles): %v", title, err)+ rfcommon.Warn("tree: duplicate title rewrite failed, keeping titles", zap.String("title", title), zap.Error(err))}}diff --git a/internal/ingestion/component/knowledge_compiler/tree/raptor.go b/internal/ingestion/component/knowledge_compiler/tree/raptor.goindex f276959a75..833ac75dfd 100644--- a/internal/ingestion/component/knowledge_compiler/tree/raptor.go+++ b/internal/ingestion/component/knowledge_compiler/tree/raptor.go@@ -16,11 +16,12 @@ package treeimport ("context""fmt"- "log""regexp""strings""time"+ "go.uber.org/zap"+rfcommon "ragflow/internal/common""ragflow/internal/ingestion/component/knowledge_compiler/common""ragflow/internal/tokenizer"@@ -70,7 +71,7 @@ func Run(ctx context.Context, deps common.Deps, param common.Param, inputs commo// here must not abort the whole tree compile — the summary nodes are already// valid on their own — so it is best-effort and surfaced as a log.if graphProds, err := buildTreeGraph(ctx, deps, docID, products); err != nil {- log.Printf("tree: graph projection failed (best-effort, continuing): %v", err)+ rfcommon.Warn("tree: graph projection failed, continuing", zap.Error(err))} else {products = append(products, graphProds...)}@@ -79,7 +80,7 @@ func Run(ctx context.Context, deps common.Deps, param common.Param, inputs commo// directly instead of only reaching them through beam descent. Also// best-effort: a failure here must not cost us the tree.if claimProds, err := buildTreeClaimProducts(ctx, deps, docID, claimsByChunk, param.TemplateID); err != nil {- log.Printf("tree: claim rows failed (best-effort, continuing): %v", err)+ rfcommon.Warn("tree: claim rows failed, continuing", zap.Error(err))} else {products = append(products, claimProds...)}@@ -212,7 +213,7 @@ func buildTree(ctx context.Context, deps common.Deps, llmID, tenantID, docID strclaimsByChunk = ExtractClaimsForChunks(ctx, deps, llmID, chunks,ParseEvidenceGateMode(param.Extra["evidence_gate_mode"]), resolveClaimPrompt(param))if len(claimsByChunk) > 0 {- log.Printf("tree: extracted claims for %d/%d chunk(s)", len(claimsByChunk), len(chunks))+ rfcommon.Info("tree: extracted claims", zap.Int("chunks_with_claims", len(claimsByChunk)), zap.Int("chunks", len(chunks)))}}if claimOut != nil {@@ -243,7 +244,7 @@ func buildTree(ctx context.Context, deps common.Deps, llmID, tenantID, docID str}if len(digests) > 0 {if claimVecs, err := deps.Embed.Encode(ctx, digests); err != nil {- log.Printf("tree: claim-view embedding failed; clustering on raw chunk vectors: %v", err)+ rfcommon.Warn("tree: claim-view embedding failed, clustering on raw chunk vectors", zap.Error(err))} else {claimView := make(map[string][]float32, len(digestIDs))for i, cid := range digestIDs {@@ -263,7 +264,7 @@ func buildTree(ctx context.Context, deps common.Deps, llmID, tenantID, docID strembeddings[i] = toFloat64Slice(view)replaced++}- log.Printf("tree: %d/%d chunk(s) clustered on claim-view embeddings", replaced, len(chunkIDs))+ rfcommon.Info("tree: clustered on claim-view embeddings", zap.Int("replaced", replaced), zap.Int("chunks", len(chunkIDs)))}}}@@ -323,7 +324,7 @@ func buildTree(ctx context.Context, deps common.Deps, llmID, tenantID, docID strif errorCount >= maxErrors {return fmt.Errorf("tree: aborted after %d summarization errors: %w", errorCount, err)}- log.Printf("tree: skipping cluster due to summarization error (continuing): %v", err)+ rfcommon.Warn("tree: skipping cluster due to summarization error", zap.Error(err))continue}nodeID := common.StableRowID(tenantID, docID, string(common.VariantTree),@@ -409,7 +410,7 @@ func buildTree(ctx context.Context, deps common.Deps, llmID, tenantID, docID str// No summaries survived (e.g. every deepest cluster failed while the// error budget was not yet exhausted). Return the partial tree without a// root node — Python drops the root in this case rather than crashing.- log.Printf("tree: no top-level summaries produced, skipping root node")+ rfcommon.Warn("tree: no top-level summaries produced, skipping root node")return nil}rootContent := buildClusterContent(topLevelTexts, allIndices(len(topLevelTexts)), deps.ModelContextLen, maxToken)@@ -419,16 +420,16 @@ func buildTree(ctx context.Context, deps common.Deps, llmID, tenantID, docID strif err != nil {// A failed root must not abort the whole tree: Python drops the root// node and returns the rest of the tree.- log.Printf("tree: root synthesis failed, skipping root node: %v", err)+ rfcommon.Warn("tree: root synthesis failed, skipping root node", zap.Error(err))return nil}embedding, err := deps.Embed.Encode(ctx, []string{rootSummary})if err != nil {- log.Printf("tree: root embedding failed, skipping root node: %v", err)+ rfcommon.Warn("tree: root embedding failed, skipping root node", zap.Error(err))return nil}if len(embedding) == 0 {- log.Printf("tree: root embedding returned no vectors, skipping root node")+ rfcommon.Warn("tree: root embedding returned no vectors, skipping root node")return nil}*products = append(*products, common.Product{diff --git a/internal/ingestion/component/media_dispatch.go b/internal/ingestion/component/media_dispatch.goindex 8fdd9cd1d6..2b2d068e22 100644--- a/internal/ingestion/component/media_dispatch.go+++ b/internal/ingestion/component/media_dispatch.go@@ -31,7 +31,6 @@ import ("encoding/base64""fmt""image"- "log/slog"// Import image decoders for common formats._ "golang.org/x/image/bmp"@@ -46,6 +45,9 @@ import ("strings""unicode/utf8"+ "go.uber.org/zap"++ "ragflow/internal/common""ragflow/internal/entity"modelModule "ragflow/internal/entity/models""ragflow/internal/ingestion/component/schema"@@ -171,8 +173,8 @@ func maybeDispatchImage(if modelRef != "" {driver, modelName, apiConfig, _, err = resolveModelConfig(ctx, db, tenantID, entity.ModelTypeImage2Text, modelRef)if err != nil {- slog.Warn("media dispatch image: per-call VLM resolve failed, falling back to tenant default",- "modelRef", modelRef, "tenant", tenantID, "err", err)+ common.Warn("media dispatch image: per-call VLM resolve failed, falling back to tenant default",+ zap.String("modelRef", modelRef), zap.String("tenant", tenantID), zap.Error(err))driver, modelName, apiConfig, _, err = resolveTenantModelByType(ctx, db, tenantID, entity.ModelTypeImage2Text)}} else {@@ -279,8 +281,8 @@ func maybeDispatchAudio(if modelRef != "" {driver, modelName, apiConfig, _, err = resolveModelConfig(ctx, db, tenantID, entity.ModelTypeSpeech2Text, modelRef)if err != nil {- slog.Warn("media dispatch audio: per-call VLM resolve failed, falling back to tenant default",- "modelRef", modelRef, "tenant", tenantID, "err", err)+ common.Warn("media dispatch audio: per-call VLM resolve failed, falling back to tenant default",+ zap.String("modelRef", modelRef), zap.String("tenant", tenantID), zap.Error(err))driver, modelName, apiConfig, _, err = resolveTenantModelByType(ctx, db, tenantID, entity.ModelTypeSpeech2Text)}} else {diff --git a/internal/ingestion/component/tokenizer.go b/internal/ingestion/component/tokenizer.goindex f1b8293e71..02f9a8dd0e 100644--- a/internal/ingestion/component/tokenizer.go+++ b/internal/ingestion/component/tokenizer.go@@ -81,7 +81,6 @@ import ("context""encoding/json""fmt"- "log""regexp""slices""strings"@@ -520,7 +519,7 @@ func (c *TokenizerComponent) embedChunks(ctx context.Context, tenantID, kbID, na// skip is the correct behavior (go_intentional). Do NOT "align" this to// the DSL.if trimmedName == "" {- log.Printf("Tokenizer: empty name provided from upstream, embedding will skip title weighting")+ common.Warn("Tokenizer: empty name provided from upstream, embedding will skip title weighting")} else {// Encode the raw name (no TrimSpace) to mirror Python// tokenizer.py:95 which passes name verbatim to embedding. Thediff --git a/internal/ingestion/component/tokenizer_test.go b/internal/ingestion/component/tokenizer_test.goindex 5703209b0e..bc4861bf89 100644--- a/internal/ingestion/component/tokenizer_test.go+++ b/internal/ingestion/component/tokenizer_test.go@@ -20,16 +20,19 @@package componentimport (- "bytes""context""errors"- "log""math""reflect""strings""testing""time"+ "go.uber.org/zap"+ "go.uber.org/zap/zapcore"+ "go.uber.org/zap/zaptest/observer"++ "ragflow/internal/common""ragflow/internal/ingestion/component/schema""ragflow/internal/tokenizer")@@ -558,15 +561,12 @@ func TestTokenizerComponent_Embedding_EmptyNameWarnsAndUsesContentVector(t *testc, stub := withStubEmbedder(t, 2)stub.resultsByCall = []embeddingCallResult{{vectors: [][]float64{{2, 4}}, tokenCount: 5}}- var buf bytes.Buffer- prevWriter := log.Writer()- prevFlags := log.Flags()- log.SetOutput(&buf)- log.SetFlags(0)- t.Cleanup(func() {- log.SetOutput(prevWriter)- log.SetFlags(prevFlags)- })+ // The empty-name warning goes through internal/common (zap), so observe it+ // by swapping the project logger instead of the stdlib global one.+ oldLogger := common.Logger+ core, logs := observer.New(zapcore.WarnLevel)+ common.Logger = zap.New(core)+ t.Cleanup(func() { common.Logger = oldLogger })out, err := c.Invoke(context.Background(), nil, map[string]any{"name": " ",@@ -580,8 +580,8 @@ func TestTokenizerComponent_Embedding_EmptyNameWarnsAndUsesContentVector(t *testif got := stub.calls.Load(); got != 1 {t.Fatalf("embedder calls = %d, want 1 (content only)", got)}- if !strings.Contains(buf.String(), "empty name provided from upstream") {- t.Fatalf("log output = %q, want empty-name warning", buf.String())+ if got := logs.FilterMessageSnippet("empty name provided from upstream").Len(); got != 1 {+ t.Fatalf("empty-name warnings = %d, want 1 (entries: %v)", got, logs.All())}got, _ := out["chunks"].([]map[string]any)want := []float64{2, 4}diff --git a/internal/ingestion/component/vision_enhancement.go b/internal/ingestion/component/vision_enhancement.goindex f237997713..ba36f432a0 100644--- a/internal/ingestion/component/vision_enhancement.go+++ b/internal/ingestion/component/vision_enhancement.go@@ -26,13 +26,14 @@ import ("encoding/base64""errors""fmt"- "log/slog""os""path/filepath""strings""sync""time"+ "go.uber.org/zap"+"ragflow/internal/common"pdflayout "ragflow/internal/deepdoc/parser/pdf/layout""ragflow/internal/entity"@@ -226,8 +227,8 @@ func maybeDispatchVisionEnhancement(if modelRef != "" {driver, modelName, apiConfig, _, err = resolveModelConfig(ctx, db, tenantID, entity.ModelTypeImage2Text, modelRef)if err != nil {- slog.Warn("vision enhancement: per-call VLM resolve failed, falling back to tenant default",- "family", family, "modelRef", modelRef, "tenant", tenantID, "err", err)+ common.Warn("vision enhancement: per-call VLM resolve failed, falling back to tenant default",+ zap.String("family", family), zap.String("modelRef", modelRef), zap.String("tenant", tenantID), zap.Error(err))driver, modelName, apiConfig, _, err = resolveTenantModelByType(ctx, db, tenantID, entity.ModelTypeImage2Text)}} else {@@ -274,8 +275,8 @@ dispatch:return}if !isUsableVisionImage(img) {- slog.Warn("vision enhancement: invalid image data skipped",- "item", itemIdx)+ common.Warn("vision enhancement: invalid image data skipped",+ zap.Int("item", itemIdx))return}messages := buildVisionMessages(prompt, img)diff --git a/internal/parser/parser/email_parser.go b/internal/parser/parser/email_parser.goindex 825b6be234..fe2c10430c 100644--- a/internal/parser/parser/email_parser.go+++ b/internal/parser/parser/email_parser.go@@ -22,7 +22,6 @@ import ("encoding/base64""fmt""io"- "log""mime""mime/multipart""mime/quotedprintable"@@ -32,9 +31,11 @@ import ("time""github.com/AkmalOt/gomsg"+ "go.uber.org/zap""golang.org/x/net/html""golang.org/x/text/transform"+ "ragflow/internal/common""ragflow/internal/utility")@@ -101,8 +102,8 @@ func (p *EmailParser) parseEmail(ctx context.Context, filename string, data []byif r := recover(); r != nil {// Log so a genuine bug (e.g. a nil deref in parseMSG)// is not silently masked as a "decode panicked" error.- log.Printf("email: .msg decode panicked for %q; skipping: %v", filename, r)err = fmt.Errorf("email: .msg decode panicked: %v", r)+ common.Error("email: .msg decode panicked, skipping", err, zap.String("file", filename))}}()msg, err = parseMSG(data, p.fields)@@ -836,7 +837,7 @@ func (p *EmailParser) rechunkEmailAttachments(ctx context.Context, content map[s// a native CGO backend) panicked. Skip just this attachment so one// bad file can't fail the whole email — mirrors the .msg// parseMSG recover.- log.Printf("email: attachment %q re-parse panicked; skipping", fn)+ common.Warn("email: attachment re-parse panicked, skipping", zap.String("file", fn))}if panicked || res.Err != nil {continuediff --git a/internal/parser/parser/office_table_render.go b/internal/parser/parser/office_table_render.goindex c7837acd3e..6307e9490b 100644--- a/internal/parser/parser/office_table_render.go+++ b/internal/parser/parser/office_table_render.go@@ -20,13 +20,15 @@ import ("encoding/base64""fmt""html"- "log/slog""regexp""sort""strconv""strings""github.com/xuri/excelize/v2"+ "go.uber.org/zap"++ "ragflow/internal/common")// tableIllegalCharsRe replaces illegal control characters (everything except@@ -270,10 +272,12 @@ func deprecatedChunkRows(setup map[string]any, parserName string) {}rows, ok := numericItemInt(raw)if !ok {- slog.Warn("spreadsheet parser ignored invalid chunk_rows; configure row merging on the chunker", "parser", parserName, "chunk_rows", raw)+ common.Warn("spreadsheet parser ignored invalid chunk_rows; configure row merging on the chunker",+ zap.String("parser", parserName), zap.Any("chunk_rows", raw))return}- slog.Warn("spreadsheet parser ignored deprecated chunk_rows; configure row merging on the chunker", "parser", parserName, "chunk_rows", rows)+ common.Warn("spreadsheet parser ignored deprecated chunk_rows; configure row merging on the chunker",+ zap.String("parser", parserName), zap.Int("chunk_rows", rows))}// extractXLSXImages returns the floating and in-cell images anchored to adiff --git a/internal/parser/parser/paddleocr.go b/internal/parser/parser/paddleocr.goindex 6ae50fe1f8..4b4e64d7fe 100644--- a/internal/parser/parser/paddleocr.go+++ b/internal/parser/parser/paddleocr.go@@ -31,13 +31,14 @@ import ("encoding/json""fmt""io"- "log/slog""mime/multipart""net/http""regexp""strings""time"+ "go.uber.org/zap"+"ragflow/internal/common")@@ -211,7 +212,7 @@ func (c *PaddleOCRClient) submitJob(binary []byte, filename string, deadline timif jobID == "" {return "", fmt.Errorf("no jobId in submit response")}- slog.Info("paddleocr: job submitted", "jobId", jobID)+ common.Info("paddleocr: job submitted", zap.String("jobId", jobID))return jobID, nil}@@ -271,7 +272,7 @@ func (c *PaddleOCRClient) pollJob(jobID string, deadline time.Time) (map[string]switch state {case "done":- slog.Info("paddleocr: job done", "jobId", jobID)+ common.Info("paddleocr: job done", zap.String("jobId", jobID))// Return full data so caller can extract resultJsonUrlvar fullData map[string]anyjson.Unmarshal(bodyBytes, &fullData)diff --git a/internal/parser/parser/pdf_parser_common.go b/internal/parser/parser/pdf_parser_common.goindex e4c50bba48..4cb485a94b 100644--- a/internal/parser/parser/pdf_parser_common.go+++ b/internal/parser/parser/pdf_parser_common.go@@ -21,7 +21,6 @@ import ("errors""fmt""image"- "log/slog""sort""strings""time"@@ -270,8 +269,8 @@ func (p *PDFParser) ConfigureFromSetup(setup map[string]any) {// should already be normalized; degrade to "parse all pages" rather// than failing the parse if an unexpected shape slips through.if pages, err := utility.NormalizePDFPages(raw); err != nil {- slog.Warn("ConfigureFromSetup: invalid pages range, falling back to all pages",- "raw", raw, "err", err)+ common.Warn("ConfigureFromSetup: invalid pages range, falling back to all pages",+ zap.Any("raw", raw), zap.Error(err))} else {p.Pages = pages}@@ -533,8 +532,8 @@ func cropMediaSections(result *deepdoctype.ParseResult) {}img, err := deepdocpdf.RenderPageToImage(engine, pn)if err != nil || img == nil {- slog.Warn("cropMediaSections: render failed, skipping section",- "page", pn, "err", err)+ common.Warn("cropMediaSections: render failed, skipping section",+ zap.Int("page", pn), zap.Error(err))pageCache[pn] = nilreturn nil}diff --git a/internal/parser/parser/xls_tcadp_test.go b/internal/parser/parser/xls_tcadp_test.goindex 568225603d..f72a517dbb 100644--- a/internal/parser/parser/xls_tcadp_test.go+++ b/internal/parser/parser/xls_tcadp_test.go@@ -1,12 +1,14 @@package parserimport (- "bytes"- "log/slog""net/http""net/http/httptest"- "strings""testing"++ "go.uber.org/zap"+ "go.uber.org/zap/zaptest/observer"++ "ragflow/internal/common")func TestXLSXParser_ParseWithResult_TCADPJSONIntegration(t *testing.T) {@@ -263,14 +265,14 @@ func TestXLSXParser_ConfigureFromSetup_TCADP(t *testing.T) {}func TestSpreadsheetParserWarnsForDeprecatedChunkRows(t *testing.T) {- var logs bytes.Buffer- previousLogger := slog.Default()- slog.SetDefault(slog.New(slog.NewTextHandler(&logs, &slog.HandlerOptions{Level: slog.LevelWarn})))- t.Cleanup(func() { slog.SetDefault(previousLogger) })+ core, logs := observer.New(zap.WarnLevel)+ originalLogger := common.Logger+ common.Logger = zap.New(core)+ t.Cleanup(func() { common.Logger = originalLogger })p := NewCSVParser()p.ConfigureFromSetup(map[string]any{"chunk_rows": 32})- if !strings.Contains(logs.String(), "deprecated chunk_rows") {- t.Fatalf("logs = %q, want deprecated chunk_rows warning", logs.String())+ if logs.FilterMessage("spreadsheet parser ignored deprecated chunk_rows; configure row merging on the chunker").Len() != 1 {+ t.Fatalf("logs = %v, want deprecated chunk_rows warning", logs.All())}}diff --git a/internal/service/chat_channel.go b/internal/service/chat_channel.goindex ee21483014..ea6ebde53f 100644--- a/internal/service/chat_channel.go+++ b/internal/service/chat_channel.go@@ -18,10 +18,11 @@ import ("context""errors""fmt"- "log""strings""sync"+ "go.uber.org/zap"+"ragflow/internal/utility""ragflow/internal/common"@@ -325,7 +326,7 @@ func (s *ChatChannelService) HandleIncomingMessage(ctx context.Context, msg Chatnil,)if err != nil {- log.Printf("chat channel %s completion failed: %v", channel.ID, err)+ common.Error("chat channel completion failed", err, zap.String("channel_id", channel.ID))return "Sorry, I couldn't process your message right now.", nil}if result == nil {diff --git a/internal/service/memory.go b/internal/service/memory.goindex 5c0512beb4..fdb1409137 100644--- a/internal/service/memory.go+++ b/internal/service/memory.go@@ -21,23 +21,23 @@ import ("context""errors""fmt"- "log/slog"- "ragflow/internal/common"- "ragflow/internal/entity"- models "ragflow/internal/entity/models"- "ragflow/internal/utility""slices""sort""strconv""strings""time"+ "go.uber.org/zap"+ "gorm.io/gorm"++ "ragflow/internal/common""ragflow/internal/dao""ragflow/internal/engine"enginetypes "ragflow/internal/engine/types"+ "ragflow/internal/entity"+ models "ragflow/internal/entity/models""ragflow/internal/service/nlp"-- "gorm.io/gorm"+ "ragflow/internal/utility")const (@@ -467,7 +467,8 @@ func (s *MemoryService) CreateMemory(ctx context.Context, tenantID string, req *if req.LLMID != "" && req.TenantLLMID == nil {target, err := modelSolver.ResolveModelConfig(ctx, tenantID, entity.ModelTypeChat, req.LLMID)if err != nil {- slog.Warn("CreateMemory: failed to resolve tenant LLM id", "tenant_id", tenantID, "llm_id", req.LLMID, "err", err)+ common.Warn("CreateMemory: failed to resolve tenant LLM id",+ zap.String("tenant_id", tenantID), zap.String("llm_id", req.LLMID), zap.Error(err))} else if target != nil && target.ModelID != "" {tenantLLMID := target.ModelIDreq.TenantLLMID = &tenantLLMID@@ -476,7 +477,8 @@ func (s *MemoryService) CreateMemory(ctx context.Context, tenantID string, req *if req.EmbdID != "" && req.TenantEmbdID == nil {target, err := modelSolver.ResolveModelConfig(ctx, tenantID, entity.ModelTypeEmbedding, req.EmbdID)if err != nil {- slog.Warn("CreateMemory: failed to resolve tenant embedding id", "tenant_id", tenantID, "embd_id", req.EmbdID, "err", err)+ common.Warn("CreateMemory: failed to resolve tenant embedding id",+ zap.String("tenant_id", tenantID), zap.String("embd_id", req.EmbdID), zap.Error(err))} else if target != nil && target.ModelID != "" {tenantEmbdID := target.ModelIDreq.TenantEmbdID = &tenantEmbdID@@ -621,7 +623,8 @@ func (s *MemoryService) UpdateMemory(ctx context.Context, tenantID string, memorif req.TenantLLMID == nil && *req.LLMID != "" {target, err := modelSolver.ResolveModelConfig(ctx, ownerTenantID, entity.ModelTypeChat, *req.LLMID)if err != nil {- slog.Warn("UpdateMemory: failed to resolve tenant LLM id", "tenant_id", ownerTenantID, "llm_id", *req.LLMID, "err", err)+ common.Warn("UpdateMemory: failed to resolve tenant LLM id",+ zap.String("tenant_id", ownerTenantID), zap.String("llm_id", *req.LLMID), zap.Error(err))} else if target != nil && target.ModelID != "" {updateDict["tenant_llm_id"] = target.ModelID}@@ -633,7 +636,8 @@ func (s *MemoryService) UpdateMemory(ctx context.Context, tenantID string, memorif req.TenantEmbdID == nil && *req.EmbdID != "" {target, err := modelSolver.ResolveModelConfig(ctx, ownerTenantID, entity.ModelTypeEmbedding, *req.EmbdID)if err != nil {- slog.Warn("UpdateMemory: failed to resolve tenant embedding id", "tenant_id", ownerTenantID, "embd_id", *req.EmbdID, "err", err)+ common.Warn("UpdateMemory: failed to resolve tenant embedding id",+ zap.String("tenant_id", ownerTenantID), zap.String("embd_id", *req.EmbdID), zap.Error(err))} else if target != nil && target.ModelID != "" {updateDict["tenant_embd_id"] = target.ModelID}diff --git a/internal/service/nav/nav_service_router.go b/internal/service/nav/nav_service_router.goindex e39e8c94f5..07c2d0eb6d 100644--- a/internal/service/nav/nav_service_router.go+++ b/internal/service/nav/nav_service_router.go@@ -28,8 +28,11 @@ package navimport ("context"- "log""strings"++ "go.uber.org/zap"++ "ragflow/internal/common")// navServiceMaxDocs is the router-local fallback doc count when the caller@@ -72,7 +75,7 @@ func (NavServiceRouter) Route(ctx context.Context, tenantID, kbID, query string,if err != nil {// A backend failure is NOT "no structure": log and let the caller fall// back rather than disabling the tool for the session.- log.Printf("[Dataset navigation search] NavService.Search failed for kb=%s: %v", kbID, err)+ common.Warn("dataset navigation search: NavService.Search failed", zap.String("kb_id", kbID), zap.Error(err))return nil, err}// Empty non-nil slice = structure exists, this query routed to nothing.diff --git a/internal/service/system.go b/internal/service/system.goindex 9d5b4c66e6..b6e335eeb6 100644--- a/internal/service/system.go+++ b/internal/service/system.go@@ -406,7 +406,7 @@ func (s *SystemService) ListAllVariables(ctx context.Context) ([]map[string]intereturn nil, err}- return common.FormatSystemSettings(settings), nil+ return entity.FormatSystemSettings(settings), nil}func (s *SystemService) ShowVariable(ctx context.Context, varName string) ([]map[string]interface{}, error) {@@ -424,7 +424,7 @@ func (s *SystemService) ShowVariable(ctx context.Context, varName string) ([]mapreturn nil, fmt.Errorf("can't get setting: %s", varName)}}- return common.FormatSystemSettings(settings), nil+ return entity.FormatSystemSettings(settings), nil}// SetVariable set variable@@ -438,7 +438,7 @@ func (s *SystemService) SetVariable(ctx context.Context, varName, varValue strinif len(settings) == 1 {setting := &settings[0]- if err = common.ValidateSystemSettingValue(*setting, varValue); err != nil {+ if err = entity.ValidateSystemSettingValue(*setting, varValue); err != nil {return err}setting.Value = varValue@@ -447,14 +447,14 @@ func (s *SystemService) SetVariable(ctx context.Context, varName, varValue strinreturn fmt.Errorf("can't update more than 1 setting: %s", varName)}- dataType := common.InferSystemSettingDataType(varName)+ dataType := entity.InferSystemSettingDataType(varName)newSetting := &entity.SystemSettings{Name: varName,Value: varValue,Source: "admin",DataType: dataType,}- if err = common.ValidateSystemSettingValue(*newSetting, varValue); err != nil {+ if err = entity.ValidateSystemSettingValue(*newSetting, varValue); err != nil {return err}return s.systemSettingsDAO.Create(ctx, dao.DB, newSetting)diff --git a/internal/storage/minio_test.go b/internal/storage/minio_test.goindex 5c69290d8f..4a8285a828 100644--- a/internal/storage/minio_test.go+++ b/internal/storage/minio_test.go@@ -21,7 +21,6 @@ package storageimport ("bytes""fmt"- "log""ragflow/internal/utility""testing""time"@@ -42,7 +41,6 @@ func getMinioConfig() (configpkg.MinioConfig, error) {// Try to get configuration from environment variables firstconfig := server.GetConfig().GetMinioConfig()- log.Printf("MinioConfig: %+v", config)return config, nil}diff --git a/internal/syncer/connector/imap.go b/internal/syncer/connector/imap.goindex 92d2bbd770..bb0c822d10 100644--- a/internal/syncer/connector/imap.go+++ b/internal/syncer/connector/imap.go@@ -26,7 +26,6 @@ import ("errors""fmt""io"- "log""net"netmail "net/mail""os"@@ -41,8 +40,10 @@ import (// Register the charset decoder so text/* parts in non-UTF-8 charsets// (e.g. ISO-8859-1, Windows-1252) are decoded to UTF-8 on read._ "github.com/emersion/go-message/charset"+ "go.uber.org/zap"xhtml "golang.org/x/net/html"+ "ragflow/internal/common""ragflow/internal/utility")@@ -205,7 +206,7 @@ func (s *imapSyncSession) NextBatch(ctx context.Context) (SyncBatch, error) {}emailDoc, attachments, err := parseIMAPMessage(raw, s.connector.sizeThreshold)if err != nil {- log.Printf("imap: skip message seq %d in mailbox %q: %v", seq, s.currentMailbox, err)+ common.Warn("imap: skip message", zap.Uint64("seq", seq), zap.String("mailbox", s.currentMailbox), zap.Error(err))continue}if !s.inWindow(emailDoc.UpdatedAt) {diff --git a/internal/syncer/connector/sitemap.go b/internal/syncer/connector/sitemap.goindex cc83e13744..f0073bdfe6 100644--- a/internal/syncer/connector/sitemap.go+++ b/internal/syncer/connector/sitemap.go@@ -24,17 +24,17 @@ import ("encoding/xml""fmt""io"- "log/slog""net/http""net/url"- "ragflow/internal/common""regexp""strings""time"- "ragflow/internal/utility"-+ "go.uber.org/zap""golang.org/x/net/html"++ "ragflow/internal/common"+ "ragflow/internal/utility")const (@@ -206,7 +206,8 @@ func (c *SitemapConnector) OpenPrune(ctx context.Context, request PruneRequest)}body, contentType, err := c.fetch(ctx, entry.loc)if err != nil {- slog.Warn("sitemap prune: failed to fetch page for PDF discovery", "url", entry.loc, "error", err)+ common.Warn("sitemap prune: failed to fetch page for PDF discovery",+ zap.String("url", entry.loc), zap.Error(err))continue}if isPDFResponse(contentType, body) {@@ -242,23 +243,25 @@ func (c *SitemapConnector) listEntries(ctx context.Context) ([]sitemapEntry, errvar walk func(sitemapURL string, depth int) errorwalk = func(sitemapURL string, depth int) error {if depth > maxSitemapDepth {- slog.Warn("sitemap: max depth reached, stopping", "url", sitemapURL)+ common.Warn("sitemap: max depth reached, stopping", zap.String("url", sitemapURL))return nil}if _, done := visited[sitemapURL]; done {- slog.Warn("sitemap: nested sitemap already visited, skipping", "url", sitemapURL)+ common.Warn("sitemap: nested sitemap already visited, skipping", zap.String("url", sitemapURL))return nil}visited[sitemapURL] = struct{}{}if fetched >= maxSitemapFetches {- slog.Warn("sitemap: maximum number of sitemap fetches reached, stopping", "url", sitemapURL, "max", maxSitemapFetches)+ common.Warn("sitemap: maximum number of sitemap fetches reached, stopping",+ zap.String("url", sitemapURL), zap.Int("max", maxSitemapFetches))return nil}if err := validateSitemapURL(sitemapURL); err != nil {if depth == 0 {return err}- slog.Warn("sitemap: skipping invalid nested sitemap URL", "url", sitemapURL, "error", err)+ common.Warn("sitemap: skipping invalid nested sitemap URL",+ zap.String("url", sitemapURL), zap.Error(err))return nil}body, _, err := c.fetch(ctx, sitemapURL)@@ -266,7 +269,8 @@ func (c *SitemapConnector) listEntries(ctx context.Context) ([]sitemapEntry, errif depth == 0 {return fmt.Errorf("failed to fetch sitemap %s: %w", sitemapURL, err)}- slog.Warn("sitemap: failed to fetch nested sitemap", "url", sitemapURL, "error", err)+ common.Warn("sitemap: failed to fetch nested sitemap",+ zap.String("url", sitemapURL), zap.Error(err))return nil}fetched++@@ -310,12 +314,12 @@ func (c *SitemapConnector) urlMatches(rawURL string) bool {// It returns nil when the page must be skipped (fetch error or empty content).func (c *SitemapConnector) buildDocument(ctx context.Context, rawURL string, lastmod time.Time, parentURL string) (*SourceDocument, []string) {if err := validateSitemapURL(rawURL); err != nil {- slog.Warn("sitemap: skipping invalid page URL", "url", rawURL, "error", err)+ common.Warn("sitemap: skipping invalid page URL", zap.String("url", rawURL), zap.Error(err))return nil, nil}body, contentType, err := c.fetch(ctx, rawURL)if err != nil {- slog.Warn("sitemap: failed to fetch page", "url", rawURL, "error", err)+ common.Warn("sitemap: failed to fetch page", zap.String("url", rawURL), zap.Error(err))return nil, nil}@@ -331,7 +335,7 @@ func (c *SitemapConnector) buildDocument(ctx context.Context, rawURL string, las)if isPDFResponse(contentType, body) {if len(body) == 0 {- slog.Debug("sitemap: empty PDF, skipping", "url", rawURL)+ common.Debug("sitemap: empty PDF, skipping", zap.String("url", rawURL))return nil, nil}blob = body@@ -342,11 +346,11 @@ func (c *SitemapConnector) buildDocument(ctx context.Context, rawURL string, las}text, err := sitemapHTMLToMarkdown(body)if err != nil {- slog.Warn("sitemap: failed to parse page", "url", rawURL, "error", err)+ common.Warn("sitemap: failed to parse page", zap.String("url", rawURL), zap.Error(err))return nil, pdfLinks}if strings.TrimSpace(text) == "" {- slog.Debug("sitemap: empty content, skipping", "url", rawURL)+ common.Debug("sitemap: empty content, skipping", zap.String("url", rawURL))return nil, pdfLinks}blob = []byte(text)@@ -665,7 +669,7 @@ func parseSitemapLastmod(value string) time.Time {return parsed.UTC()}}- slog.Debug("sitemap: unrecognised lastmod format", "value", value)+ common.Debug("sitemap: unrecognised lastmod format", zap.String("value", value))return time.Time{}}diff --git a/internal/syncer/connector/zotero.go b/internal/syncer/connector/zotero.goindex 2332b7a27b..d5dd6dcb27 100644--- a/internal/syncer/connector/zotero.go+++ b/internal/syncer/connector/zotero.go@@ -24,7 +24,6 @@ import ("errors""fmt""io"- "log/slog""net/http""net/url""path/filepath"@@ -32,6 +31,10 @@ import ("strconv""strings""time"++ "go.uber.org/zap"++ "ragflow/internal/common")const (@@ -261,10 +264,10 @@ func (c *ZoteroConnector) collectPDFRecords(ctx context.Context, request SyncReq}updatedAt, err := zoteroParseTime(item.Data.DateModified)if err != nil {- slog.Warn(+ common.Warn("zotero: using fallback timestamp for attachment with invalid dateModified",- "item_key", item.Key,- "error", err,+ zap.String("item_key", item.Key),+ zap.Error(err),)updatedAt = time.Unix(0, 0).UTC()}@@ -620,26 +623,26 @@ func (s *zoteroSyncSession) handleDownloadFailure(record zoteroPDFRecord,reason string,documentsLen int,- attrs ...any,+ attrs ...zap.Field,) (breakBatch bool, advanceIndex bool) {s.downloadFailures++key := record.attachment.Keys.downloadAttempts[key]++- args := []any{- "item_key", key,- "source_id", s.connector.sourceID(key),- "attempt", s.downloadAttempts[key],- "max_attempts", zoteroMaxDownloadAttemptsPerAttachment,+ args := []zap.Field{+ zap.String("item_key", key),+ zap.String("source_id", s.connector.sourceID(key)),+ zap.Int("attempt", s.downloadAttempts[key]),+ zap.Int("max_attempts", zoteroMaxDownloadAttemptsPerAttachment),}args = append(args, attrs...)- slog.Warn("zotero: "+reason, args...)+ common.Warn("zotero: "+reason, args...)if s.downloadAttempts[key] >= zoteroMaxDownloadAttemptsPerAttachment {- slog.Warn(+ common.Warn("zotero: permanently skipping attachment after repeated download failures",- "item_key", key,- "source_id", s.connector.sourceID(key),- "attempts", s.downloadAttempts[key],+ zap.String("item_key", key),+ zap.String("source_id", s.connector.sourceID(key)),+ zap.Int("attempts", s.downloadAttempts[key]),)return false, true}@@ -667,7 +670,7 @@ func (s *zoteroSyncSession) NextBatch(ctx context.Context) (SyncBatch, error) {record,"attachment download failed",len(documents),- "error", err,+ zap.Error(err),)if advanceIndex {s.index++@@ -683,7 +686,7 @@ func (s *zoteroSyncSession) NextBatch(ctx context.Context) (SyncBatch, error) {record,"skipping oversized attachment",len(documents),- "bytes", len(blob),+ zap.Int("bytes", len(blob)),)if advanceIndex {s.index++@@ -700,7 +703,8 @@ func (s *zoteroSyncSession) NextBatch(ctx context.Context) (SyncBatch, error) {if len(documents) == 0 {if s.index >= len(s.records) {if s.downloadFailures > 0 {- slog.Warn("zotero: sync completed with attachment download failures", "count", s.downloadFailures)+ common.Warn("zotero: sync completed with attachment download failures",+ zap.Int("count", s.downloadFailures))}return SyncBatch{}, io.EOF}