Files
aresv2/config/loger.go
Beyhan Oğur 4362c3b83f first commit
2026-04-26 21:33:39 +03:00

40 lines
1.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package configs
import (
"os"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var Logger *zap.Logger
func init() {
// initialize default logger early so other packages can use it in their init functions
LogerAres()
}
func LogerAres() {
logFile, err := os.Create("./info.log")
if err != nil {
// Fallback: sadece konsola yaz
core := zapcore.NewCore(
zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()),
zapcore.AddSync(os.Stdout),
zapcore.DebugLevel,
)
Logger = zap.New(core, zap.AddCaller())
Logger.Warn("info.log açılamadı, sadece konsola yazılıyor", zap.Error(err))
return
}
// Hem dosyaya hem konsola yaz (logları görebilirsin)
encoderConfig := zap.NewProductionEncoderConfig()
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
encoder := zapcore.NewConsoleEncoder(encoderConfig)
multiOut := zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(logFile))
core := zapcore.NewCore(encoder, multiOut, zapcore.DebugLevel)
Logger = zap.New(core, zap.AddCaller())
Logger.Info("Logger başlatıldı (konsol + info.log)")
}