Logging
log, debug, and error are the three console builtins. They take any number of args, send each through Rat's JSON encoder, and route to console.log / console.debug / console.error in the browser. Server-tier calls (inside > server or in service handlers) print to the server's stdout with 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; the console receives it as-is. Strings, numbers, booleans, arrays, objects — all fine.
<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
Variadic — 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 survive the trip
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. In most browsers it's filtered out of the default console view — toggle the verbose filter to see entries. Use it for trace-level output you want available but not in 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 — bad input, unreachable state — so production users hitting them are visible 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; no special "server log" builtin. This is the location-transparency property in action — one name, multiple compile targets.
> server
tag: log('rendering /home for', request.path)
> service [page_views]
after[req]
log('served', req.url, 'in', req.duration_ms, 'ms') Next: Inspection — len, type, keys, values, has for poking at values at runtime.