From f884ff1f845bfb6652e9f3ce9dff64b8756f929a Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 8 Jul 2025 15:49:54 -0400 Subject: [PATCH] feat(log): add atomic check for initialization --- internal/log/log.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/log/log.go b/internal/log/log.go index 31c183e9d7274d35ad2d70c7c1f5418586bc5a2d..8d2583cdabb0a6d4184137e25e36bf253d86d858 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -6,12 +6,16 @@ import ( "os" "runtime/debug" "sync" + "sync/atomic" "time" "gopkg.in/natefinch/lumberjack.v2" ) -var initOnce sync.Once +var ( + initOnce sync.Once + initialized atomic.Bool +) func Init(logFile string, debug bool) { initOnce.Do(func() { @@ -34,9 +38,14 @@ func Init(logFile string, debug bool) { }) slog.SetDefault(slog.New(logger)) + initialized.Store(true) }) } +func IsInitialized() bool { + return initialized.Load() +} + func RecoverPanic(name string, cleanup func()) { if r := recover(); r != nil { // Create a timestamped panic log file