aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-faster/errors/trace.go
blob: 3cf4689ef2c0e2396c8d7a092d6968d929c20359 (plain) (blame)
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
//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
}