trace.go 747 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //go:build !noerrtrace
  2. // +build !noerrtrace
  3. package errors
  4. import (
  5. "sync/atomic"
  6. )
  7. var traceFlag int64
  8. const (
  9. traceEnabled = 0 // enabled by default
  10. traceDisabled = 1
  11. )
  12. // setTrace sets tracing flag that controls capturing caller frames.
  13. func setTrace(trace bool) {
  14. if trace {
  15. atomic.StoreInt64(&traceFlag, traceEnabled)
  16. } else {
  17. atomic.StoreInt64(&traceFlag, traceDisabled)
  18. }
  19. }
  20. // enableTrace enables capturing caller frames.
  21. //
  22. // Intentionally left unexported.
  23. func enableTrace() { setTrace(true) }
  24. // DisableTrace disables capturing caller frames.
  25. func DisableTrace() { setTrace(false) }
  26. // Trace reports whether caller stack capture is enabled.
  27. func Trace() bool {
  28. return atomic.LoadInt64(&traceFlag) == traceEnabled
  29. }