Read logs
Write log lines from a handler, read them with luna logs, narrow them to one luna or call, and follow new lines as they arrive.
A handler runs on Luna’s machines, so its console.log never reaches your terminal on its own. Luna keeps every line your code writes, tags it with the call that wrote it, and adds lines of its own about calls that fail.
Write a log line
Use console in any handler. Each line is kept with its level.
import { defineLuna, t, table } from "luna";
export const List = defineLuna({
name: "List",
visibility: "public",
key: { id: t.string() },
schema: {
items: table({ id: t.id(), text: t.string() }),
},
handlers: (h) => ({
add: h({ args: { text: t.string() } }, (ctx, { text }) => {
if (text.length > 200) console.warn("long item", text.length);
ctx.db.items.insert({ text });
console.log("added", text, "to", ctx.key.id);
}),
}),
});
| Method | Level |
|---|---|
console.debug, console.trace |
debug |
console.log, console.info |
info |
console.warn |
warn |
console.error |
error |
Luna tags each line with the luna type, the key, the handler, the call’s id, its trace and the version of the code. A line longer than 16 KiB is cut there and ends with …. In Python, print and the logging module are kept the same way, as Write lunas in Python shows.
Read the last hour
In your app’s folder, run luna logs.
luna logs
It prints the newest 200 lines of the last hour, oldest first. Each line has its time, its level, the luna and handler that wrote it, and the text.
Narrow the lines
Name a luna type, and add filters to find the lines you need.
luna logs List --key groceries --level warn
| Option | Does |
|---|---|
TYPE |
Only lines of this luna type |
--key |
Only one luna: its whole key, or the value of one of its key’s fields |
--level |
This level and above: debug, info, warn or error |
--grep |
Only lines that contain this text. Text in lower case matches any case |
--call |
Only the lines of one call, by its id |
--trace |
Only the lines of one trace, by its id |
A handler can read its own call’s id in ctx.callId and its trace’s id in ctx.traceId.
Follow new lines
Pass --follow, or -f, to keep printing lines as they are written. Stop it with Ctrl+C.
luna logs List --follow
The filters work the same way while following. luna dev follows the environment’s lines for you, as Develop with luna dev shows.
Read Luna’s own lines
Beside your code’s lines, Luna writes lines about what happens to each luna. Pass --source luna for those alone, or --source code for your code’s lines alone.
luna logs --source luna --event call --outcome error
--event takes one or more of these, separated by commas.
| Event | The line tells of |
|---|---|
call |
A call, message or hook that failed, ran past its caller’s deadline, or took 500 ms or more |
wake, sleep, move |
A luna waking, leaving memory or moving to another machine |
version |
A luna moving to a new version of the code, or failing to |
timeout, refused |
A call that ran out of time, or one turned away before it ran |
deadLetter, retry |
A message set aside after its last attempt, or a durable step tried again |
crash, sandbox |
A luna that failed outside a call, or a sandbox that started, stopped or failed |
destroy, restore |
A luna destroyed, or rewound to an earlier moment |
A call that succeeds in under 500 ms gets no line of its own. Their counts and times are in luna status. --outcome keeps the call lines that went one way: ok, error or timeout.
Look further back
Set the window with --since and --until. Each takes a length such as 15m, a phrase such as "2h ago", a time such as 2026-11-09T10:00:00Z, or milliseconds since the epoch.
luna logs --since "2d ago" --until "1d ago" --limit 1000
When more lines match than --limit, you get the newest ones. A request returns 5,000 lines at most. Luna keeps logs and traces for 7 days.
Process lines as JSON
Pass --json to print each line as a JSON object, one a line, for a script or an agent.
luna logs --json --level error
| Field | Holds |
|---|---|
tsMs |
When the line was written, in milliseconds since the epoch |
level |
debug, info, warn or error |
body |
The text |
lunaType, key, handler |
Who wrote it. key is the luna’s key as JSON |
callId, traceId, spanId, version |
The call, trace, span and code version it belongs to |
source, event |
luna and the event, on Luna’s own lines |
attrs |
More fields, such as a call line’s outcome, durationUs and error |
A field with nothing to say is left out.
Next steps
- Follow traces shows where a call’s time went across lunas.
- Check status shows calls, errors and latency for each luna type.
- Return errors shows how a handler fails on purpose.