Documentation
¶
Overview ¶
Package diag records crash reports and optional routine debug traces. It is deliberately stdlib-only so any layer may import it, and it records a short operation label rather than raw arguments, so a report never contains a secret.
Index ¶
- Constants
- func Catch(op string)
- func LatestReport(data []byte) []byte
- func Report(v any, op string) (string, error)
- func SetDebug(on bool)
- func SetDefault(r *Recorder)
- func SetMode(mode string)
- func SetModel(model string)
- func SetOp(op string)
- func Tracef(format string, args ...any)
- type Options
- type Recorder
- func (r *Recorder) Catch(op string)
- func (r *Recorder) Close() error
- func (r *Recorder) CrashPath() string
- func (r *Recorder) DebugPath() string
- func (r *Recorder) Debugf(format string, args ...any)
- func (r *Recorder) Report(v any, op string) (string, error)
- func (r *Recorder) SetDebug(on bool)
- func (r *Recorder) SetMode(mode string)
- func (r *Recorder) SetModel(model string)
- func (r *Recorder) SetOp(op string)
Constants ¶
const ( CrashFile = "crash.log" DebugFile = "debug.log" )
The file names under the configuration directory.
const Header = "=== nova crash report ==="
Header marks the start of a crash report so a viewer can find the most recent one in an appended file.
Variables ¶
This section is empty.
Functions ¶
func Catch ¶
func Catch(op string)
Catch recovers a panic in the calling goroutine and records it with the default recorder. With no recorder it prints a one-line error to stderr, so a panic is never silent. Use it as `defer diag.Catch("operation")`.
func LatestReport ¶
LatestReport returns the last crash report in data, or data unchanged when it holds no report marker.
func Report ¶
Report records a panic through the default recorder and returns the crash file path. It is the package-level form of Recorder.Report for code that has no recorder to hand.
func SetDebug ¶
func SetDebug(on bool)
SetDebug turns routine tracing on the default recorder on or off, if any.
func SetDefault ¶
func SetDefault(r *Recorder)
SetDefault installs the process-wide recorder. Passing nil clears it.
func SetMode ¶
func SetMode(mode string)
SetMode records the active mode on the default recorder, if any.
func SetModel ¶
func SetModel(model string)
SetModel records the active model on the default recorder, if any.
Types ¶
type Options ¶
type Options struct {
Dir string
Version string
Mode string
Model string
Debug bool
// MaxBytes is how large a log may grow before it moves aside to <name>.1; zero
// means 4 MiB.
MaxBytes int64
// Now and Stack are seams for tests.
Now func() time.Time
Stack func() []byte
}
Options configures a Recorder. Dir, when set, is the directory that holds CrashFile and DebugFile; when empty, reports cannot be written.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder writes crash reports and, when debug is on, routine trace lines. It is safe for concurrent use, because the agent loop, the provider, and the extension host all run on their own goroutines.
func Default ¶
func Default() *Recorder
Default returns the process-wide recorder, or nil before startup sets one.
func New ¶
New builds a Recorder. The zero Options is valid: it records nothing and is useful only to keep callers from branching on nil.
func (*Recorder) Catch ¶
Catch recovers a panic in the calling goroutine and records it with this Recorder. Use it as `defer r.Catch("operation")` at the top of a goroutine.
func (*Recorder) CrashPath ¶
CrashPath is the crash file path, or empty when no directory was configured.
func (*Recorder) DebugPath ¶
DebugPath is the debug file path, or empty when no directory was configured.
func (*Recorder) Debugf ¶
Debugf appends a timestamped trace line when debug is on. It never creates the debug file until the first line is written.
func (*Recorder) Report ¶
Report formats and appends one crash report and returns the file path, so the caller can tell the user where to look. op overrides any operation set with SetOp; when empty, the last operation is used.