-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
39 lines (33 loc) · 977 Bytes
/
debug.go
File metadata and controls
39 lines (33 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package comet
import (
"os"
"strings"
"sync/atomic"
)
// debugEnabled controls whether debug logging is enabled (using atomic for thread safety)
var debugEnabled int32
func init() {
// Check environment variable for debug mode
debugEnv := os.Getenv("COMET_DEBUG")
if debugEnv != "" && debugEnv != "0" && strings.ToLower(debugEnv) != "false" {
atomic.StoreInt32(&debugEnabled, 1)
}
}
// SetDebug allows runtime control of debug mode
func SetDebug(enabled bool) {
if enabled {
atomic.StoreInt32(&debugEnabled, 1)
} else {
atomic.StoreInt32(&debugEnabled, 0)
}
}
// IsDebug returns whether debug mode is enabled (thread-safe)
func IsDebug() bool {
// Check atomic flag first (fastest path)
if atomic.LoadInt32(&debugEnabled) == 1 {
return true
}
// Also check environment variable dynamically (slower but handles runtime changes)
debugEnv := os.Getenv("COMET_DEBUG")
return debugEnv != "" && debugEnv != "0" && strings.ToLower(debugEnv) != "false"
}