Skip to main content
Fairyfly ships one logging primitive: console. This page is about using it well.

Redirecting output

All console output is stderr, which makes separation trivial:
There is no process.stdout.write and no other API that touches fd 1 — every log line lands on stderr. For a shipper that insists on stdout, merge at the shell:
Otherwise treat console as your log sink and let the supervisor collect stderr (Docker and systemd both capture it by default).

Levels

Use the built-in colours as levels:

Structured, single-line JSON

For machines, serialize one object per line — collectors (Vector, Loki, CloudWatch) ingest that shape directly:

Timing requests

For anything tighter than ~1 ms, use performance.now():

Logging errors without losing the stack

Inside an http.serve handler, an uncaught throw becomes a 500 — log first, then rethrow.

In a Worker

Workers have their own console, writing to the same stderr:

Gotchas

  • console.log({ a: 1 }) prints [object Object] — use JSON.stringify.
  • ANSI colour codes survive redirection into files; strip them at the collector if your format requires it.
  • Nothing flushes aggressively — if the process is killed, the last line in a pipe may be lost. For crash-only diagnostics, prefer writing to a file with fs.writeFile.
  • There is no log-level filtering: every call prints. Gate noisy output yourself (if (debug) console.debug(...)).

See also