Skip to main content
FrontMCP logging is extensible. In addition to the default console logger, you can register one or more custom transports via the server config.

Register a transport

Transport contract

A transport is a class decorated with @LogTransport({...}) that implements LogTransportInterface.
The framework filters by the configured 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.
Disable it by setting 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.
Register it:

Example: HTTP batch transport (non‑blocking)

Buffer records in memory and POST them in batches. Implements basic retry with backoff.
Notes:
  • Keep batches small and time‑bounded; avoid blocking the event loop.
  • On process exit, you may add a beforeExit/SIGTERM handler to flush synchronously.

Prefixes and levels

  • logging.prefix adds a static scope tag to all records (e.g., app name or environment).
  • Transports receive rec.level and rec.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 Error objects explicitly (name, message, stack).
  • Apply backpressure: if the sink is down, drop or sample rather than blocking the server.