You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
747 B
37 lines
747 B
//go:build !noerrtrace |
|
// +build !noerrtrace |
|
|
|
package errors |
|
|
|
import ( |
|
"sync/atomic" |
|
) |
|
|
|
var traceFlag int64 |
|
|
|
const ( |
|
traceEnabled = 0 // enabled by default |
|
traceDisabled = 1 |
|
) |
|
|
|
// setTrace sets tracing flag that controls capturing caller frames. |
|
func setTrace(trace bool) { |
|
if trace { |
|
atomic.StoreInt64(&traceFlag, traceEnabled) |
|
} else { |
|
atomic.StoreInt64(&traceFlag, traceDisabled) |
|
} |
|
} |
|
|
|
// enableTrace enables capturing caller frames. |
|
// |
|
// Intentionally left unexported. |
|
func enableTrace() { setTrace(true) } |
|
|
|
// DisableTrace disables capturing caller frames. |
|
func DisableTrace() { setTrace(false) } |
|
|
|
// Trace reports whether caller stack capture is enabled. |
|
func Trace() bool { |
|
return atomic.LoadInt64(&traceFlag) == traceEnabled |
|
}
|
|
|