mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 15:31:05 +08:00
refactor(log): unify Go logging to zap with rotation, strip per-package levels (#16261)
Refactor the Go agent port's logging so every log line — gin access, agent canvas events, harness warnings, fatal boot errors — flows through a single common.Logger (zap) backed by a rotated file, with structured fields, level filtering, and configurable rotation. --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -74,7 +74,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Initialize logger
|
||||
if err := common.Init("info", "admin_server.log"); err != nil {
|
||||
if err := common.Init("info", common.FileOutput{Path: "admin_server.log"}); err != nil {
|
||||
panic("failed to initialize logger: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -96,7 +96,17 @@ func main() {
|
||||
logLevel = "debug"
|
||||
}
|
||||
|
||||
if err := common.Init(logLevel, "admin_server.log"); err != nil {
|
||||
fileOut := common.FileOutput{
|
||||
Path: "admin_server.log",
|
||||
MaxSize: cfg.Log.MaxSize,
|
||||
MaxBackups: cfg.Log.MaxBackups,
|
||||
MaxAge: cfg.Log.MaxAge,
|
||||
Compress: common.ResolveCompress(cfg.Log.Compress),
|
||||
}
|
||||
if cfg.Log.Path != "" {
|
||||
fileOut.Path = cfg.Log.Path
|
||||
}
|
||||
if err := common.Init(logLevel, fileOut); err != nil {
|
||||
common.Error("Failed to reinitialize logger with configured level", err)
|
||||
}
|
||||
|
||||
@@ -158,15 +168,8 @@ func main() {
|
||||
ginEngine := gin.New()
|
||||
|
||||
// Middleware
|
||||
if cfg.Server.Mode == "debug" {
|
||||
ginEngine.Use(gin.Logger())
|
||||
}
|
||||
ginEngine.Use(common.GinLogger())
|
||||
ginEngine.Use(gin.Recovery())
|
||||
// Log request URL for every request
|
||||
ginEngine.Use(func(c *gin.Context) {
|
||||
common.Info("HTTP Request", zap.String("url", c.Request.URL.String()), zap.String("method", c.Request.Method))
|
||||
c.Next()
|
||||
})
|
||||
|
||||
// Setup routes
|
||||
r.Setup(ginEngine)
|
||||
|
||||
@@ -90,7 +90,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Initialize logger with default level
|
||||
if err := common.Init("info", "ingestion_server.log"); err != nil {
|
||||
if err := common.Init("info", common.FileOutput{Path: "ingestion_server.log"}); err != nil {
|
||||
panic(fmt.Sprintf("Failed to initialize logger: %v", err))
|
||||
}
|
||||
|
||||
@@ -123,7 +123,17 @@ func main() {
|
||||
level = "debug"
|
||||
}
|
||||
|
||||
if err := common.Init(level, "ingestion_server.log"); err != nil {
|
||||
fileOut := common.FileOutput{
|
||||
Path: "ingestion_server.log",
|
||||
MaxSize: config.Log.MaxSize,
|
||||
MaxBackups: config.Log.MaxBackups,
|
||||
MaxAge: config.Log.MaxAge,
|
||||
Compress: common.ResolveCompress(config.Log.Compress),
|
||||
}
|
||||
if config.Log.Path != "" {
|
||||
fileOut.Path = config.Log.Path
|
||||
}
|
||||
if err := common.Init(level, fileOut); err != nil {
|
||||
common.Error("Failed to reinitialize logger", err)
|
||||
}
|
||||
server.SetLogger(common.Logger)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//go:build ignore
|
||||
|
||||
//
|
||||
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
|
||||
//
|
||||
@@ -45,7 +46,7 @@ func main() {
|
||||
logLevel = "info"
|
||||
}
|
||||
|
||||
if err = common.Init(logLevel, ""); err != nil {
|
||||
if err = common.Init(logLevel, common.FileOutput{}); err != nil {
|
||||
fmt.Printf("Warning: Failed to initialize logger: %v\n", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ func main() {
|
||||
|
||||
// Initialize logger with default level
|
||||
// logger.Init("info"); // set debug log level
|
||||
if err := common.Init("info", "server_main.log"); err != nil {
|
||||
if err := common.Init("info", common.FileOutput{Path: "server_main.log"}); err != nil {
|
||||
panic(fmt.Sprintf("Failed to initialize logger: %v", err))
|
||||
}
|
||||
|
||||
@@ -122,7 +122,17 @@ func main() {
|
||||
level = "debug"
|
||||
}
|
||||
|
||||
if err := common.Init(level, "server_main.log"); err != nil {
|
||||
fileOut := common.FileOutput{
|
||||
Path: "server_main.log",
|
||||
MaxSize: config.Log.MaxSize,
|
||||
MaxBackups: config.Log.MaxBackups,
|
||||
MaxAge: config.Log.MaxAge,
|
||||
Compress: common.ResolveCompress(config.Log.Compress),
|
||||
}
|
||||
if config.Log.Path != "" {
|
||||
fileOut.Path = config.Log.Path
|
||||
}
|
||||
if err := common.Init(level, fileOut); err != nil {
|
||||
common.Error("Failed to reinitialize logger", err)
|
||||
}
|
||||
server.SetLogger(common.Logger)
|
||||
@@ -317,9 +327,10 @@ func startServer(config *server.Config) {
|
||||
ginEngine := gin.New()
|
||||
|
||||
// Middleware
|
||||
if config.Server.Mode == "debug" {
|
||||
ginEngine.Use(gin.Logger())
|
||||
}
|
||||
// Note: common.GinLogger() is registered inside router.Setup so the
|
||||
// HTTP request log captures every endpoint the router owns (including
|
||||
// those registered by Setup itself). Registering it here would run
|
||||
// it twice for those endpoints and double every access-log line.
|
||||
ginEngine.Use(gin.Recovery())
|
||||
|
||||
// Setup routes
|
||||
|
||||
Reference in New Issue
Block a user