-
Notifications
You must be signed in to change notification settings - Fork 3
/
debug.go
57 lines (51 loc) · 1.43 KB
/
debug.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Package debug provides general debug feature management for Gio, including
// the ability to toggle debug features using the GIODEBUG environment variable.
package debug
import (
"fmt"
"os"
"strings"
"sync"
"sync/atomic"
)
const (
debugVariable = "GIODEBUG"
textSubsystem = "text"
silentFeature = "silent"
)
// Text controls whether the text subsystem has debug logging enabled.
var Text atomic.Bool
var parseOnce sync.Once
// Parse processes the current value of GIODEBUG. If it is unset, it does nothing.
// Otherwise it process its value, printing usage info the stderr if the value is
// not understood. Parse will be automatically invoked when the first application
// window is created, allowing applications to manipulate GIODEBUG programmatically
// before it is parsed.
func Parse() {
parseOnce.Do(func() {
val, ok := os.LookupEnv(debugVariable)
if !ok {
return
}
print := false
silent := false
for _, part := range strings.Split(val, ",") {
switch part {
case textSubsystem:
Text.Store(true)
case silentFeature:
silent = true
default:
print = true
}
}
if print && !silent {
fmt.Fprintf(os.Stderr,
`Usage of %s:
A comma-delimited list of debug subsystems to enable. Currently recognized systems:
- %s: text debug info including system font resolution
- %s: silence this usage message even if GIODEBUG contains invalid content
`, debugVariable, textSubsystem, silentFeature)
}
})
}