logger updated

This commit is contained in:
mercierj 2025-12-07 00:27:30 -04:00
parent 20ee14599e
commit c312cb79ba

View File

@ -17,9 +17,34 @@ import (
// Log instancia global del logger
var Log = logrus.New()
type LocalTimeHook struct {
loc *time.Location
}
func (h LocalTimeHook) Levels() []logrus.Level {
return logrus.AllLevels
}
func (h LocalTimeHook) Fire(e *logrus.Entry) error {
if h.loc != nil {
e.Time = e.Time.In(h.loc)
}
return nil
}
func InitLogger(cfg *Config) {
// =========================
// Zona horaria Bolivia
// =========================
loc, err := time.LoadLocation("America/La_Paz")
if err != nil {
// Fallback robusto para contenedores sin tzdata
loc = time.FixedZone("America/La_Paz", -4*60*60)
}
time.Local = loc
// Hook para forzar timestamps de Logrus a hora Bolivia
Log.AddHook(LocalTimeHook{loc: loc})
// Configurar rotación de logs con Lumberjack
rotator := &lumberjack.Logger{
Filename: cfg.LogFilePath, // Archivo de logs