Documentation
¶
Overview ¶
zdebug provides additional features of standard runtime/debug package.
Build Tags: - zdebugdump : Enables [Dump] function to work. Environmental Variables: - GO_ZDEBUG=<value> - "file" : Output debug messages into a temporal file (case insensitive). - "stdout" : Output debug messages into the standard output (case insensitive). - "stderr" : Output debug messages into the standard error (case insensitive). - "discard" : Discard all debug messages (case insensitive). - other values are ignored.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DumpConfig is the dump output format configuration. // See the documents on [spew.ConfigState]. DumpConfig = spew.ConfigState{Indent: " "} )
var ( // HookDumpFunc hooks [Dump] function. // HookDumpFunc is called when applications are run or built // with runtime dump enabled. // HookDumpFunc receives [io.Writer] that should be used for log output // if necessary and caller fame information in [zruntime.Frame] format. // In addition to them, all arguments given to the [Dump] are also given. // If HookDumpFunc returned true, the [Dump] function immediately returns // without running default procession of if. // Use build tag `//go:build !zdebugdump` to enable runtime dump. HookDumpFunc func(io.Writer, zruntime.Frame, ...any) bool = nil )
Functions ¶
func Dump ¶
Dump prints object dump of the given values. Use build time tags "-tags zdebugdump" to enable output. Stdout is used as default output destination. If callers who wants to debug temporarily without build tags, use DumpAlways or DumpTo instead.
func DumpAlways ¶
DumpAlways prints object dump of the given values. Unlike Dump, it does not requires build tags.
func DumpTo ¶
DumpTo writes dump results into the given writer. The writer will be reset after DumpTo returned. Unlike the Dump, DumpTo does not requires build tag.
Example ¶
package main import ( "bytes" "fmt" "strings" "github.com/aileron-projects/go/zruntime/zdebug" ) func main() { val := struct { foo int bar string }{ foo: 123, bar: "bar", } var buf bytes.Buffer zdebug.DumpTo(&buf, "", val) output := buf.String() _, output, _ = strings.Cut(output, "\n") // Discard first line. _, output, _ = strings.Cut(output, "\n") // Discard second line. fmt.Println(string(output)) }
Output: | ┌── args[0] | (struct { foo int; bar string }) { | foo: (int) 123, | bar: (string) (len=3) "bar" | }
func GoDebugEnv ¶
GoDebugEnv returns the value of GODEBUG which has the given key. When GODEBUG=foo=bar,alice=bob GoDebugEnv("foo") returns "bar", GoDebugEnv("alice") returns "bob". GoDebugEnv returns true when the given key was found in the GODEBUG env and returns false when not found. GoDebugEnv does not trim or remove any spaces. So, if GODEBUG="foo=bar, alice=bob" then GoDebugEnv("alice") returns false.
Types ¶
This section is empty.