Pengambilan Data KFA Pengiriman data medication dan service request
This commit is contained in:
No files matched your search
+35
-1
@@ -16,6 +16,35 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// localLoc adalah zona waktu yang dipakai untuk seluruh log timestamp dan rotasi
|
||||
// file harian. Default-nya Asia/Jakarta (WIB +07:00); fallback ke offset tetap
|
||||
// jika data tzdata tidak tersedia di sistem.
|
||||
var localLoc = func() *time.Location {
|
||||
if loc, err := time.LoadLocation("Asia/Jakarta"); err == nil {
|
||||
return loc
|
||||
}
|
||||
return time.FixedZone("WIB", 7*3600)
|
||||
}()
|
||||
|
||||
// localTimeHook mengubah entry.Time ke zona waktu lokal sebelum formatter dipanggil,
|
||||
// sehingga timestamp di JSON formatter maupun customFormatter sama-sama WIB.
|
||||
type localTimeHook struct{ loc *time.Location }
|
||||
|
||||
func (h *localTimeHook) Levels() []logrus.Level { return logrus.AllLevels }
|
||||
func (h *localTimeHook) Fire(entry *logrus.Entry) error {
|
||||
entry.Time = entry.Time.In(h.loc)
|
||||
return nil
|
||||
}
|
||||
|
||||
// LocalLocation mengembalikan zona waktu lokal yang dipakai logger (Asia/Jakarta).
|
||||
// Berguna ketika kode lain perlu memformat tanggal/waktu mengikuti zona yang sama.
|
||||
func LocalLocation() *time.Location { return localLoc }
|
||||
|
||||
// LocalNow mengembalikan waktu sekarang dalam zona waktu lokal (WIB). Pakai ini
|
||||
// daripada time.Now() ketika hasilnya dipakai untuk nama file harian/bulanan agar
|
||||
// pergantian hari sesuai jam lokal, bukan UTC.
|
||||
func LocalNow() time.Time { return time.Now().In(localLoc) }
|
||||
|
||||
// Logger interface mendefinisikan kontrak untuk logging
|
||||
type Logger interface {
|
||||
Debug(message string, fields ...Field)
|
||||
@@ -159,6 +188,9 @@ func New(cfg Config) Logger {
|
||||
}
|
||||
logrusLogger.SetOutput(output)
|
||||
|
||||
// Pasang hook agar semua entry.Time di-convert ke WIB sebelum formatter dipanggil.
|
||||
logrusLogger.AddHook(&localTimeHook{loc: localLoc})
|
||||
|
||||
// Set default fields
|
||||
entry := logrusLogger.WithFields(logrus.Fields{
|
||||
"service": cfg.ServiceName,
|
||||
@@ -379,7 +411,9 @@ func (w *dailyFileWriter) Write(p []byte) (n int, err error) {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
|
||||
now := time.Now()
|
||||
// Rotasi mengikuti zona waktu lokal (WIB) agar file harian berganti tepat
|
||||
// pada 00:00 WIB, bukan 00:00 UTC.
|
||||
now := time.Now().In(localLoc)
|
||||
dateStr := now.Format("2006-01-02") // Format harian (YYYY-MM-DD)
|
||||
|
||||
// Cek jika hari berganti atau file belum terbuka
|
||||
|
||||
Reference in New Issue
Block a user