///
Welcome to Zario, a minimal, fast, and feature-rich logging library for Node.js. This guide will help you get Zario up and running in your project, covering basic installation, logger initialization,
41 views
~41 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.
Welcome to Zario, a minimal, fast, and feature-rich logging library for Node.js. This guide will help you get Zario up and running in your project, covering basic installation, logger initialization, and common logging practices. For a deeper dive into Zario's philosophy and features, please refer to our [Introduction] page.
Getting started with Zario is straightforward. You can install the package using npm:
Let's begin with a simple example to illustrate how to initialize a logger and output messages to the console.
In the quick start example, we've initialized a basic Zario logger. Let's break down the key components:
The core of Zario is the Logger class. You create an instance by passing a configuration object to its constructor:
Once you have a Logger instance, you can use its intuitive methods to emit log messages. The example demonstrates info(), warn(), and error():
logger.info("🚀 Server started on port 3000"): Used for general informational messages about application flow.logger.warn("⚠️ High memory usage detected"): Indicates potential issues or non-critical errors that might need attention.logger.error("❌ Database connection failed", { code: 500 }): Reports critical errors that impact functionality. It also demonstrates how to include arbitrary metadata (an object { code: 500 }) with your log messages for structured logging.Zario also includes debug(), boring(), and silent() levels for more granular control over log verbosity.
The transports option determines where your logs will be sent. A transport is an object responsible for outputting the formatted log data to a specific destination.
transports: [new ConsoleTransport()]: In this example, we're using ConsoleTransport, which directs all logs to the standard console output (e.g., console.log, console.warn, console.error).FileTransport (for writing to files with rotation and compression) and HttpTransport (for sending logs to remote HTTP endpoints) for more advanced scenarios.colorizeThe colorize option controls whether log messages should include ANSI color codes for better readability in terminals:
colorize: true: Enables colored output for log levels (e.g., errors in red, warnings in yellow). This is generally preferred in development environments.colorize: false: Disables colorization, resulting in plain text output. This is often suitable for production environments or when logs are ingested by other systems.prefixThe prefix option allows you to add a consistent string at the beginning of each log message, useful for identifying logs from specific applications or components:
prefix: "[MyApp]": Prepends [MyApp] to all log messages from this logger instance.Zario is designed with sensible defaults that adapt to your environment, reducing boilerplate configuration. Based on your NODE_ENV environment variable:
NODE_ENV=development or unset):
level: debug (verbose logging).colorize: true.json: false (plain text).asyncMode: false (synchronous writes).transports: ConsoleTransport only.NODE_ENV=production or NODE_ENV=prod):
level: warn (only warnings and errors).colorize: false.json: true (structured JSON output).asyncMode: true (asynchronous, non-blocking writes).transports: ConsoleTransport and FileTransport (writing to ./logs/app.log).You can always override these defaults by explicitly setting options in the Logger constructor, as shown in the Quick Start example.