on main help sign in
feat(log): add atomic check for initialization
commitf884ff1f845bfb6652e9f3ce9dff64b8756f929a authorAyman Bagabas <ayman.bagabas@gmail.com> dateTue 8 Jul 2025, 15:49 (1 year ago) parentf4c7c5c
1 file changed+10−1
internal/log/log.go+10−1
internal/log/log.go+10−1
@@ -6,12 +6,16 @@ import (
66 "os"
77 "runtime/debug"
88 "sync"
9+ "sync/atomic"
910 "time"
1011
1112 "gopkg.in/natefinch/lumberjack.v2"
1213)
1314
14−var initOnce sync.Once
15+var (
16+ initOnce sync.Once
17+ initialized atomic.Bool
18+)
1519
1620func Init(logFile string, debug bool) {
1721 initOnce.Do(func() {
@@ -34,9 +38,14 @@ func Init(logFile string, debug bool) {
3438 })
3539
3640 slog.SetDefault(slog.New(logger))
41+ initialized.Store(true)
3742 })
3843}
3944
45+func IsInitialized() bool {
46+ return initialized.Load()
47+}
48+
4049func RecoverPanic(name string, cleanup func()) {
4150 if r := recover(); r != nil {
4251 // Create a timestamped panic log file