///
Zario offers extensive configuration options to tailor its logging behavior to your application's needs. This page details all available options for the `Logger` class and its built-in transports.
40 views
~40 views from guests
Guest views are estimated from total page views. These include anonymous visitors and users who weren't logged in when they viewed the page.
Zario offers extensive configuration options to tailor its logging behavior to your application's needs. This page details all available options for the Logger class and its built-in transports.
LoggerOptions)The Logger class constructor accepts an options object of type LoggerOptions ([API Reference - LoggerOptions]).
Here's a breakdown of each option:
level?: LogLevel
'debug' in development environments (NODE_ENV is development, test, staging, or unset).'warn' in production environments (NODE_ENV is production or prod).'debug', 'info', 'warn', 'error', 'silent', 'boring', or any custom log level you define.colorize?: boolean
true in development environments.false in production environments.true | falsejson?: boolean
false (text format) in development environments.true (JSON format) in production environments.true (structured JSON) | false (plain text)transports?: TransportConfig[]
[new ConsoleTransport()] in development environments.[new ConsoleTransport(), new FileTransport({ path: "./logs/app.log" })] in production environments.Transport instances (e.g., ConsoleTransport, FileTransport, HttpTransport, or custom transports).timestamp?: boolean
truetrue | falsetimestampFormat?: string
timestamp is true."YYYY-MM-DD HH:mm:ss""ISO": ISO 8601 format (e.g., 2023-10-27T10:30:00.000Z)"UTC": UTC string format (e.g., Fri, 27 Oct 2023 10:30:00 GMT)"LOCAL": Localized date/time string (e.g., 10/27/2023, 1:30:00 PM)YYYY (year), MM (month), DD (day), HH (hour), mm (minute), ss (second), SSS (milliseconds).prefix?: string
"" (empty string)context?: Record<string, any>
metadata of every log message generated by this logger. This is useful for adding consistent contextual information (e.g., requestId, userId).{} (empty object)asyncMode?: boolean
false in development environments.true in production environments.true | falseparent?: Logger
Logger instance. If provided, the new logger will inherit settings (level, transports, prefix, context, etc.) from the parent. This is primarily used internally by createChild().undefinedlogger.createChild())
customLevels?: { [level: string]: number }
debug, info, warn, error, silent, boring.{} (empty object)customColors?: { [level: string]: string }
colorize is true.{} (uses Zario's default colors for standard levels)'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', or their bright counterparts (e.g., 'brightRed').filters?: Filter[]
Filter instances. These filters are applied to each log message before it is sent to transports or aggregators. If any filter in the array returns false (meaning it should not emit), the log message is discarded.[] (no filters)PredicateFilter, LevelFilter, PrefixFilter, MetadataFilter, FieldFilter, CompositeFilter, OrFilter, NotFilter ([API Reference - Filters]).aggregators?: LogAggregator[]
LogAggregator instances. Aggregators collect log messages (e.g., for batching) before a final processing step.[] (no aggregators)BatchAggregator, TimeBasedAggregator, CompositeAggregator ([API Reference - Aggregation]).enrichers?: LogEnrichmentPipeline
LogEnrichmentPipeline that contains a series of LogEnricher functions. Enrichers modify or add data to the log record's metadata before it's formatted and sent to transports/aggregators.LogEnrichmentPipeline instance.LogEnrichmentPipeline populated with MetadataEnricher static methods or custom LogEnricher functions ([API Reference - Structured Logging Extensions]).Each built-in transport also has its own configuration options.
ConsoleTransportOptionsOptions for the ConsoleTransport class.
colorize?: boolean
colorize setting specifically for this console transport. If true, this transport will output colored logs even if the logger's colorize is false (and vice-versa).truetrue | falseFileTransportOptionsOptions for the FileTransport class.
path: string
maxSize?: number
10 * 1024 * 1024 (10 MB)maxFiles?: number
5compression?: CompressionType
'none''gzip', 'deflate', 'none'batchInterval?: number
0 (default), logs are written immediately. Setting a value greater than 0 can improve performance by reducing file I/O operations.0 (no batching)compressOldFiles?: boolean
compression is enabled.truetrue | falseHttpTransportOptionsOptions for the HttpTransport class.
url: string
method?: string
'POST'headers?: Record<string, string>
{ 'Content-Type': 'application/json' }timeout?: number
5000 (5 seconds)retries?: number
3Zario allows you to define your own log levels and associate them with custom colors, providing greater semantic control over your logging.
Use the customLevels option in LoggerOptions. Each entry maps a custom level name (string) to a numeric priority. Standard levels have default priorities:
silent: 0boring: 1debug: 2info: 3warn: 4error: 5Use the customColors option in LoggerOptions. Each entry maps a log level name (built-in or custom) to an ANSI color string.
Zario intelligently auto-configures default LoggerOptions based on the NODE_ENV environment variable, aiming to provide sensible defaults for different deployment environments.
NODE_ENV = development, test, staging, or unset)If NODE_ENV is set to development, test, staging, or is not set at all, Zario applies the following defaults:
level: 'debug' (Logs all messages down to debug severity)colorize: true (Console output will be colored)json: false (Logs will be in plain text format)transports: [new ConsoleTransport()] (Logs only to the console)timestamp: true (Timestamps are included in logs)asyncMode: false (Logs are written synchronously)This setup is ideal for local development, providing verbose, human-readable output directly in your terminal.
NODE_ENV = production or prod)If NODE_ENV is set to production or prod (case-insensitive), Zario optimizes for production deployments:
level: 'warn' (Logs only warnings and errors to reduce noise)colorize: false (No colors, as production logs often go to files or structured logging systems)json: true (Logs are in structured JSON format, suitable for log aggregation tools)transports: [new ConsoleTransport(), new FileTransport({ path: "./logs/app.log" })] (Logs to both console and a file for persistence)timestamp: true (Timestamps are included)asyncMode: true (Logs are written asynchronously to minimize impact on application performance)This configuration ensures efficient, machine-readable logging that is less disruptive to your live application.
You can always explicitly set any LoggerOptions property in the Logger constructor to override these environment-based defaults. Your explicit settings will take precedence.
When creating [child loggers], they inherit settings from their parent, and any options provided to createChild() will override those inherited settings. This allows for fine-grained control over logging behavior across different parts of your application while maintaining a consistent base configuration.