Register a transport
Transport contract
A transport is a class decorated with@LogTransport({...}) that implements LogTransportInterface.
logging.level before calling transports.
Transports should never throw. Handle errors internally and keep I/O non‑blocking (use buffering/batching for remote sinks).
Built‑in: Console
The default console transport formats messages with ANSI (when TTY) and falls back to plain text otherwise.enableConsole: false in your server config.
Example: Structured JSON (JSONL)
Emit machine‑readable logs (one JSON per line). Useful for file shipping agents or centralized logging.Example: HTTP batch transport (non‑blocking)
Buffer records in memory and POST them in batches. Implements basic retry with backoff.- Keep batches small and time‑bounded; avoid blocking the event loop.
- On process exit, you may add a
beforeExit/SIGTERMhandler to flush synchronously.
Prefixes and levels
logging.prefixadds a static scope tag to all records (e.g., app name or environment).- Transports receive
rec.levelandrec.levelName; the framework already filtered below‑level logs.
Best practices
- Never throw from
log(); swallow and self‑heal. - Avoid heavy sync I/O; prefer buffering and async flush.
- Redact sensitive fields before emit (tokens, PII).
- Serialize
Errorobjects explicitly (name, message, stack). - Apply backpressure: if the sink is down, drop or sample rather than blocking the server.