internal/logger/README.md
This package provides structured logging using Uber's Zap library.
Install zap dependency:
go get go.uber.org/zap
The logger is initialized in cmd/server_main.go and is available throughout the application.
import (
"ragflow/internal/logger"
"go.uber.org/zap"
)
// Log with structured fields
logger.Info("User login", zap.String("user_id", userID), zap.String("ip", clientIP))
// Log error
logger.Error("Failed to connect database", err)
// Log fatal (exits application)
logger.Fatal("Failed to start server", err)
// Debug level
logger.Debug("Processing request", zap.String("request_id", reqID))
// Warning level
logger.Warn("Slow query", zap.Duration("duration", duration))
If you need the underlying Zap logger:
logger.Logger.Info("Message", zap.String("key", "value"))
Or use the SugaredLogger for more flexible API:
logger.Sugar.Infow("Message", "key", "value")
If zap is not installed or fails to initialize, the logger will fallback to the standard library log package, ensuring the application continues to work.
The logger supports the following levels:
debug - Detailed information for debugginginfo - General informational messageswarn - Warning messageserror - Error messagesfatal - Fatal errors that stop the applicationThe log level is configured via the server mode in the configuration:
debug mode uses debug levelrelease mode uses info level