mirror of
https://github.com/Dvorinka/Trackeep.git
synced 2026-06-03 20:12:58 +00:00
feat: migrate to DragonflyDB and clean up environment configuration
- Replace Redis with DragonflyDB for better performance and memory efficiency - Remove redundant environment variables (POSTGRES_*, ENCRYPTION_KEY, OAUTH_SERVICE_URL) - Consolidate database configuration to use single DB_* variables - Use JWT_SECRET for both JWT tokens and encryption - Remove PORT variable redundancy, use BACKEND_PORT consistently - Clean up docker-compose configurations for dev/prod consistency - Add DragonflyDB configuration with optimized memory usage - Remove redis.conf as it's no longer needed - Update health checks to use Redis-compatible CLI for DragonflyDB - Add missing VITE_API_URL to production frontend - Fix GitHub Actions to use correct go.sum path - Clean up development directories and unused files
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
var Logger *zap.Logger
|
||||
|
||||
// InitLogger initializes the Zap logger
|
||||
func InitLogger() {
|
||||
// Get log level from environment
|
||||
logLevel := os.Getenv("LOG_LEVEL")
|
||||
if logLevel == "" {
|
||||
logLevel = "info"
|
||||
}
|
||||
|
||||
// Parse log level
|
||||
var level zapcore.Level
|
||||
switch logLevel {
|
||||
case "debug":
|
||||
level = zapcore.DebugLevel
|
||||
case "info":
|
||||
level = zapcore.InfoLevel
|
||||
case "warn":
|
||||
level = zapcore.WarnLevel
|
||||
case "error":
|
||||
level = zapcore.ErrorLevel
|
||||
default:
|
||||
level = zapcore.InfoLevel
|
||||
}
|
||||
|
||||
// Check if we're in production mode
|
||||
isProduction := os.Getenv("GIN_MODE") == "release"
|
||||
|
||||
// Configure encoder
|
||||
var encoder zapcore.Encoder
|
||||
encoderConfig := zap.NewProductionEncoderConfig()
|
||||
encoderConfig.TimeKey = "timestamp"
|
||||
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||
encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
|
||||
|
||||
if isProduction {
|
||||
encoder = zapcore.NewJSONEncoder(encoderConfig)
|
||||
} else {
|
||||
encoder = zapcore.NewConsoleEncoder(encoderConfig)
|
||||
}
|
||||
|
||||
// Configure output
|
||||
writeSyncer := zapcore.AddSync(os.Stdout)
|
||||
|
||||
// Create core
|
||||
core := zapcore.NewCore(encoder, writeSyncer, level)
|
||||
|
||||
// Create logger
|
||||
Logger = zap.New(core, zap.AddCaller(), zap.AddStacktrace(zapcore.ErrorLevel))
|
||||
|
||||
// Replace global logger
|
||||
zap.ReplaceGlobals(Logger)
|
||||
|
||||
Logger.Info("Logger initialized",
|
||||
zap.String("level", logLevel),
|
||||
zap.Bool("production", isProduction),
|
||||
)
|
||||
}
|
||||
|
||||
// GetLogger returns the configured logger instance
|
||||
func GetLogger() *zap.Logger {
|
||||
if Logger == nil {
|
||||
// Fallback to default logger if not initialized
|
||||
logger, _ := zap.NewProduction()
|
||||
return logger
|
||||
}
|
||||
return Logger
|
||||
}
|
||||
|
||||
// SyncLogger flushes any buffered log entries
|
||||
func SyncLogger() {
|
||||
if Logger != nil {
|
||||
_ = Logger.Sync()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user