This page provides a detailed reference for the core classes and methods in Zario.
The primary class for creating loggers. Provides error event notification via onError() for transport, aggregator, and enricher failures.
new Logger(options?: LoggerOptions)
(isProd: boolean) => TransportConfig[] | null
Overrides environment-based default transport selection.
(options: RetryTransportOptions) => Transport | null
Factory used when retryOptions is provided on LoggerOptions.
Root zario import configures this automatically.
Registers a callback for errors in the logging pipeline (transports, aggregators, or enrichers).
- Payload:
{ type: string, error: unknown } - Types:
'transport','aggregator','enricher'
logger.onError(({ type, error }) => {
console.error(`Error in ${type}:`, error);
});The Logger no longer extends EventEmitter, reducing per-instance overhead.
All logging methods accept a message string and an optional metadata object.
debug(message, metadata?)info(message, metadata?)warn(message, metadata?)error(message, metadata?)fatal(message, metadata?)boring(message, metadata?)silent(message, metadata?)logWithLevel(level: string, message: string, metadata?: object): Log using a custom level name.
Creates a new logger instance that inherits the configuration of the current logger. The new options are merged with the parent's.
- Prefixes are appended (e.g.,
[Parent][Child]). - Context is merged.
- Transports, Filters, and Enrichers are inherited.
Starts a performance timer. Returns a Timer object.
timer.end(): Ends the timer and logs the duration (e.g.,Database query took 150ms).
Dynamically adds or removes a filter from the logger.
Dynamically adds or removes an aggregator.
Adds an enrichment function or object to the structured logging pipeline.
Toggles asynchronous logging mode at runtime.
Manually flushes all registered aggregators. Useful before application shutdown.
Returned by logger.startTimer().
end(): Calculates elapsed time sincestartTimerwas called and logs it usinglogger.info(). It is idempotent; subsequent calls do nothing.
An union type of built-in levels: 'silent' | 'boring' | 'debug' | 'info' | 'warn' | 'error' | 'fatal'.
Equivalent to RetryTransportOptions without wrappedTransport.
Used in LoggerOptions.retryOptions.
Interface for log transports. See Transports for implementations.
path: string - Target file path.maxSize?: number - Maximum file size before rotation.maxFiles?: number - Maximum number of rotated files to keep.compression?:'gzip' | 'deflate' | 'none'- Compression type.compressOldFiles?: boolean - Whether to compress old files.batchInterval?: number - Buffer writes in milliseconds (0 to disable).maxQueueSize?: number - Maximum number of items in the batch queue for memory safety. Default:10000.
url: string - Remote endpoint.method?: string - HTTP method (default:'POST').headers?: object - HTTP headers.timeout?: number - Request timeout in ms.retries?: number - Number of retries on failure.forceAsync?: boolean - Force asynchronous behavior even when calling synchronouswrite()method.
threshold?: number - Failure count before tripping circuit breaker (default:5).timeout?: number - Time in ms to wait in half-open state (default:60000).resetTimeout?: number - Auto-reset timer in ms.onStateChange?: function - Callback for state changes:(fromState: string, toState: string) => void.onTrip?: function - Callback when circuit trips:(failureCount: number) => void.onReset?: function - Callback when circuit resets:() => void.
transport: Transport - Required. Transport to wrap.maxRetries?: number - Maximum retry attempts (default:3).retryableErrorCodes?: string[] - Error codes worth retrying (default: network errors).deadLetterFile?: string - File path to store failed logs.onDeadLetter?: function - Callback for captured dead letters:(deadLetter: DeadLetterLog) => void.
Extends LogData with additional dead letter metadata:
deadLetterReason: string - Human-readable error message.originalError?: string - Error code from original failure.retryCount: number - Number of retry attempts made.failedAt: Date - When the log failed permanently.
See Advanced Usage for aggregator details.
maxSize: number - Number of logs to collect before flushing.flushCallback: function - Callback to handle the batch of logs.maxQueueSize?: number - Maximum number of logs to keep in memory queue. Default:10000.
flushInterval: number - Time interval in ms between flushes.flushCallback: function - Callback to handle the batch of logs.maxQueueSize?: number - Maximum number of logs to keep in memory queue. Default:10000.