Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v0 source pure

Package debug provides utilities for logging and displaying debug information within Gno realms. It supports conditio...

Readme View source

gno.land/p/moul/debug

A debug panel for realms: collect log lines while Render runs, then append them as a collapsible section, but only when the reader asks for it with ?debug=1.

1func Render(path string) string {
2	var d debug.Debug
3	d.Log("loaded " + ufmt.Sprintf("%d", n) + " items")
4
5	out := renderPage()
6	out += d.Render(path)    // empty unless ?debug=1
7	return out
8}

Without the query parameter the panel renders nothing, so the same code is safe to leave in a deployed realm: there is no debug build and no flag to flip.

API

1func (d *Debug) Log(line string)       // append one line
2func (d Debug) Render(path string) string
3func Render(path string) string        // metadata only, no logs
4func IsEnabled(path string) bool       // is ?debug=1 set
5func ToggleURL(path string) string     // same path with ?debug=1 added or removed

The struct is two fields, Logs []string and HideMetadata bool, so the zero value already works and metadata is on unless you turn it off.

The metadata table reports the current realm's pkgpath and address, the previous realm's pkgpath and address, the block height, and time.Now(). Those six are what you need first when a realm behaves differently on chain than it did in a test, and the previous-realm pair in particular is what a cross-realm permission bug looks like.

ToggleURL is there so the page can render its own "debug" link:

1out += md.Link("debug", debug.ToggleURL(path))

Logs cost nothing on chain: they are built during a Render query and thrown away with it. Do not call Log from a transaction path expecting persistence.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

Dependency graph:

gno.land/p/moul/debug/v0 dependency graph

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.

Overview

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`.

Functions 3

func IsEnabled

1func IsEnabled(path string) bool
source

IsEnabled checks if the `?debug=1` query parameter is set in the given path. Returns true if debugging is enabled, otherwise false.

func Render

1func Render(path string) string
source

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 ToggleURL

1func ToggleURL(path string) string
source

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.

Types 1

type Debug

struct
1type Debug struct {
2	Logs         []string
3	HideMetadata bool
4}
source

Debug encapsulates debug information, including logs and metadata.

Methods on Debug

func Log

method on Debug
1func (d *Debug) Log(line string)
source

Log appends a new line of debug information to the Logs slice.

func Render

method on Debug
1func (d Debug) Render(path string) string
source

Render generates the debug content as a collapsible Markdown section. It conditionally renders logs and metadata if enabled via the `?debug=1` query parameter.

Dependencies

Source Files 4