@@ -39,9 +39,9 @@ var errTraceSyntax = errors.New("expect file.go:234")
39
39
type GlogHandler struct {
40
40
origin Handler // The origin handler this wraps
41
41
42
- level uint32 // Current log level, atomically accessible
43
- override uint32 // Flag whether overrides are used, atomically accessible
44
- backtrace uint32 // Flag whether backtrace location is set
42
+ level atomic. Uint32 // Current log level, atomically accessible
43
+ override atomic. Bool // Flag whether overrides are used, atomically accessible
44
+ backtrace atomic. Bool // Flag whether backtrace location is set
45
45
46
46
patterns []pattern // Current list of patterns to override with
47
47
siteCache map [uintptr ]Lvl // Cache of callsite pattern evaluations
@@ -72,7 +72,7 @@ type pattern struct {
72
72
// Verbosity sets the glog verbosity ceiling. The verbosity of individual packages
73
73
// and source files can be raised using Vmodule.
74
74
func (h * GlogHandler ) Verbosity (level Lvl ) {
75
- atomic . StoreUint32 ( & h .level , uint32 (level ))
75
+ h .level . Store ( uint32 (level ))
76
76
}
77
77
78
78
// Vmodule sets the glog verbosity pattern.
@@ -138,7 +138,7 @@ func (h *GlogHandler) Vmodule(ruleset string) error {
138
138
139
139
h .patterns = filter
140
140
h .siteCache = make (map [uintptr ]Lvl )
141
- atomic . StoreUint32 ( & h .override , uint32 (len (filter )) )
141
+ h .override . Store (len (filter ) != 0 )
142
142
143
143
return nil
144
144
}
@@ -171,7 +171,7 @@ func (h *GlogHandler) BacktraceAt(location string) error {
171
171
defer h .lock .Unlock ()
172
172
173
173
h .location = location
174
- atomic . StoreUint32 ( & h .backtrace , uint32 (len (location )) )
174
+ h .backtrace . Store (len (location ) > 0 )
175
175
176
176
return nil
177
177
}
@@ -180,7 +180,7 @@ func (h *GlogHandler) BacktraceAt(location string) error {
180
180
// and backtrace filters, finally emitting it if either allow it through.
181
181
func (h * GlogHandler ) Log (r * Record ) error {
182
182
// If backtracing is requested, check whether this is the callsite
183
- if atomic . LoadUint32 ( & h .backtrace ) > 0 {
183
+ if h .backtrace . Load () {
184
184
// Everything below here is slow. Although we could cache the call sites the
185
185
// same way as for vmodule, backtracing is so rare it's not worth the extra
186
186
// complexity.
@@ -198,11 +198,11 @@ func (h *GlogHandler) Log(r *Record) error {
198
198
}
199
199
}
200
200
// If the global log level allows, fast track logging
201
- if atomic . LoadUint32 ( & h .level ) >= uint32 (r .Lvl ) {
201
+ if h .level . Load ( ) >= uint32 (r .Lvl ) {
202
202
return h .origin .Log (r )
203
203
}
204
204
// If no local overrides are present, fast track skipping
205
- if atomic . LoadUint32 ( & h .override ) == 0 {
205
+ if ! h .override . Load () {
206
206
return nil
207
207
}
208
208
// Check callsite cache for previously calculated log levels
0 commit comments