Pure package detail
debug
gno.land/p/moul/debug/v2
Indexed deployment identity with independently loaded latest RPC source. Functions and Render are realm-only RPC capabilities.
Indexed deployment
Identity
- Package path
- gno.land/p/moul/debug/v2
- Block
- 23353
- Deployed (UTC)
- Transaction
- PPfY2gHEbYVYCPUW5wpz3iRqGOxkjJn15tP5Bous/yY=
Latest RPC state
Source
// Package debug provides utilities for logging and displaying debug information
// within Gno realms. It supports conditional rendering of logs and metadata,
// toggleable via query parameters.
//
// Key Features:
// - Log collection and display using Markdown formatting.
// - Metadata display for realm path, address, and height.
// - Collapsible debug section for cleaner presentation.
// - Query-based debug toggle using `?debug=1`.
package debug
import (
"chain/runtime"
"chain/runtime/unsafe"
"time"
"gno.land/p/moul/md/v1"
"gno.land/p/moul/mdtable/v1"
"gno.land/p/moul/realmpath/v1"
"gno.land/p/nt/ufmt/v0"
)
// Debug encapsulates debug information, including logs and metadata.
type Debug struct {
Logs []string
HideMetadata bool
}
// Log appends a new line of debug information to the Logs slice.
func (d *Debug) Log(line string) {
d.Logs = append(d.Logs, line)
}
// Render generates the debug content as a collapsible Markdown section.
// It conditionally renders logs and metadata if enabled via the `?debug=1` query parameter.
func (d Debug) Render(path string) string {
if realmpath.Parse(path).Query.Get("debug") != "1" {
return ""
}
var content string
if d.Logs != nil {
content += md.H3("Logs")
content += md.BulletList(d.Logs)
}
if !d.HideMetadata {
content += md.H3("Metadata")
table := mdtable.Table{
Headers: []string{"Key", "Value"},
}
table.Append([]string{"`std.CurrentRealm().PkgPath()`", string(unsafe.CurrentRealm().PkgPath())})
table.Append([]string{"`std.CurrentRealm().Address()`", string(unsafe.CurrentRealm().Address())})
table.Append([]string{"`std.PreviousRealm().PkgPath()`", string(unsafe.PreviousRealm().PkgPath())})
table.Append([]string{"`std.PreviousRealm().Address()`", string(unsafe.PreviousRealm().Address())})
table.Append([]string{"`std.ChainHeight()`", ufmt.Sprintf("%d", runtime.ChainHeight())})
table.Append([]string{"`time.Now().Format(time.RFC3339)`", time.Now().Format(time.RFC3339)})
content += table.String()
}
if content == "" {
return ""
}
return md.CollapsibleSection("debug", content)
}
// Render displays metadata about the current realm but does not display logs.
// This function uses a default Debug struct with metadata enabled and no logs.
func Render(path string) string {
return Debug{}.Render(path)
}
// IsEnabled checks if the `?debug=1` query parameter is set in the given path.
// Returns true if debugging is enabled, otherwise false.
func IsEnabled(path string) bool {
req := realmpath.Parse(path)
return req.Query.Get("debug") == "1"
}
// ToggleURL modifies the given path's query string to toggle the `?debug=1` parameter.
// If debugging is currently enabled, it removes the parameter.
// If debugging is disabled, it adds the parameter.
func ToggleURL(path string) string {
req := realmpath.Parse(path)
if IsEnabled(path) {
req.Query.Del("debug")
} else {
req.Query.Add("debug", "1")
}
return req.String()
}
The verified vm/qfuncs operation accepts realm paths only.
Pure packages expose source files but do not have Realm Render.