-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.go
More file actions
124 lines (90 loc) · 2.23 KB
/
runtime.go
File metadata and controls
124 lines (90 loc) · 2.23 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package debugo
import (
"io"
"os"
"sync"
)
type Format string
const (
Plain Format = "plain"
JSON Format = "json"
)
type config struct {
namespace string
timestamp *Timestamp
output io.Writer
useColors bool
format Format
mutex *sync.RWMutex
}
var runtime = &config{
namespace: "*",
timestamp: nil,
output: os.Stderr,
useColors: true,
format: Plain,
mutex: &sync.RWMutex{},
}
type Timestamp struct {
Format string
}
// SetFormat sets the global output format for debugging.
func SetFormat(format Format) {
runtime.mutex.Lock()
defer runtime.mutex.Unlock()
runtime.format = format
}
// GetFormat retrieves the current global output format for debugging.
func GetFormat() Format {
runtime.mutex.RLock()
defer runtime.mutex.RUnlock()
return runtime.format
}
// SetUseColors sets the global color usage for debugging.
func SetUseColors(use bool) {
runtime.mutex.Lock()
defer runtime.mutex.Unlock()
runtime.useColors = use
}
// GetUseColors retrieves the current global color usage for debugging.
func GetUseColors() bool {
runtime.mutex.RLock()
defer runtime.mutex.RUnlock()
return runtime.useColors
}
// SetNamespace sets the global namespace for debugging.
func SetNamespace(namespace string) {
runtime.mutex.Lock()
defer runtime.mutex.Unlock()
runtime.namespace = namespace
}
// GetNamespace retrieves the current global namespace for debugging.
func GetNamespace() string {
runtime.mutex.RLock()
defer runtime.mutex.RUnlock()
return runtime.namespace
}
// SetTimestamp sets the global timestamp configuration for debugging.
func SetTimestamp(timestamp *Timestamp) {
runtime.mutex.Lock()
defer runtime.mutex.Unlock()
runtime.timestamp = timestamp
}
// GetTimestamp retrieves the current global timestamp configuration for debugging.
func GetTimestamp() *Timestamp {
runtime.mutex.RLock()
defer runtime.mutex.RUnlock()
return runtime.timestamp
}
// SetOutput sets the global output configuration for debugging.
func SetOutput(output io.Writer) {
runtime.mutex.Lock()
defer runtime.mutex.Unlock()
runtime.output = output
}
// GetOutput retrieves the current global output configuration for debugging.
func GetOutput() io.Writer {
runtime.mutex.RLock()
defer runtime.mutex.RUnlock()
return runtime.output
}