Logging
log, debug, and error are the three console builtins. Each takes any number of args, sends each through Rat's JSON encoder, and routes to console.log, console.debug, or console.error in the browser. Server-tier calls (inside > server or service handlers) print to the server's stdout in the same shape. Open the browser console (F12) before clicking the buttons below.
log a literal
Console: hello
The simplest call. Pass the value directly and the console receives it as-is. Strings, numbers, booleans, arrays, and objects all work.
<button on_click[log['hello']]> log "hello"
<button on_click[log[42]]> log 42 log a state value
Reads the current page state at click time
Naming a state var inside the handler reads the live value when the handler fires, not when the page rendered. Bump the counter, then log. The printed number reflects the latest write.
> page
p_count: 0
<button on_click[p_count++]> +1
<button on_click[log[p_count]]> log p_count
<p> [p_count] 0
Multiple args in one call
Console: name: Ada count: 0
Pass multiple arguments separated by commas. The console renders them inline, the same way console.log(a, b, c) does. Useful for labelled traces: a short string tag followed by the value you care about.
<button on_click[log['name:', p_name, 'count:', p_count]]> log mixed Log a composite value
Arrays and objects keep their structure
Containers are encoded as JSON before going through the channel and decoded back as live JS values on the console side. You get an inspectable object, not its string form.
> page
people: [{name: 'Ada', age: 36}, {name: 'Grace', age: 85}]
<button on_click[log[people]]> log people debug: devtools-only channel
Console.debug; hidden behind the verbose filter by default
debug routes to console.debug. Most browsers hide it from the default console view, so toggle the verbose filter to see entries. Use it for trace-level output you want available but out of the way.
<button on_click[debug['cycle complete']]> debug error: red entries, stack trace
Console.error; surfaces in the browser error panel
error routes to console.error. Browsers render the entry in red and, depending on devtools settings, attach a stack trace pointing back at the handler. Use it for genuine failures like bad input or unreachable state. Users hitting them then show up in error monitors.
<button on_click[error['validation failed:', p_name]]> error Server-tier logging
Same call, prints to server stdout
Calling log(...) from a > server block, a service handler, or a middleware hook prints to the process running rat start. Same arg shape. There is no separate "server log" builtin: one name compiles to multiple targets.
> server
tag: log('rendering /home for', request.path)
> service [page_views]
after[req]
log('served', req.url, 'in', req.duration_ms, 'ms') See also Inspection · Parser errors · Middleware