@faremeter/logs provides a lightweight logging abstraction used across all faremeter packages. It supports pluggable backends, log levels, and structured context objects.
Basic usage
Get a logger without any explicit configuration. The library auto-resolves a backend (LogtapeBackend if @logtape/logtape is installed, otherwise ConsoleBackend).
subsystem array passed to getLogger identifies the component producing the log entry. Backends use this for filtering and categorization.
Configuring the app
CallconfigureApp once at startup to set the log level and optionally choose a backend:
ConfigureAppArgs
| Option | Type | Default | Description |
|---|---|---|---|
level | LogLevel | "info" | Minimum log level to emit. |
backend | LoggingBackend | Auto-resolved | Logging backend to use. |
Log levels
TheLogLevels constant defines all available levels in order of increasing severity:
| Level | Use case |
|---|---|
trace | Fine-grained debugging (RPC calls, serialization). |
debug | Development diagnostics. |
info | Normal operational events. |
warning | Recoverable issues that may need attention. |
error | Failures that prevent an operation from completing. |
fatal | Unrecoverable errors requiring shutdown. |
Context objects
Every log method accepts an optional context object as the second argument:Record<string, unknown>). Backends determine how context is rendered.
Custom backend
Implement theLoggingBackend interface to route logs to any destination:
configureApp:
LogtapeBackend
For structured logging in production, use theLogtapeBackend from @faremeter/logs/logtape. This is the default backend when @logtape/logtape is installed.
LogtapeBackend integrates with the logtape ecosystem, enabling file sinks, JSON formatting, and other logtape transports.
Further reading
- Fetch Wrapper — The fetch wrapper uses
@faremeter/logsinternally. - @faremeter/logs API Reference — Full API reference.