Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 17, 2026·3 min de lecture

Consola — Elegant Console Logger for Node.js and Browser

A universal logging utility that provides beautiful console output with log levels, tag-based filtering, and browser compatibility. Part of the UnJS ecosystem that powers Nuxt and Nitro.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Consola
Commande d'installation directe
npx -y tokrepo@latest install 4921cf35-81b9-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Consola is a console logging utility designed for Node.js and browser environments. It replaces raw console.log calls with structured, leveled output that includes timestamps, color coding, and tag-based filtering. Created as part of the UnJS project, it is the default logger for Nuxt, Nitro, and other tools in that ecosystem.

What Consola Does

  • Provides leveled logging methods: fatal, error, warn, log, info, success, debug, trace
  • Renders formatted output with colors, icons, and box drawing characters in terminals
  • Falls back gracefully to plain console methods in browser environments
  • Supports tagged loggers for isolating output from different modules
  • Offers interactive prompts for confirmation, text input, and selection

Architecture Overview

Consola uses a reporter-based architecture. Log calls create structured log objects with level, tag, timestamp, and arguments. Reporters receive these objects and format them for the target environment. The default FancyReporter renders colored terminal output, while the BrowserReporter uses native console methods. Custom reporters can be registered for log shipping or file output.

Self-Hosting & Configuration

  • Install via npm and import the consola singleton or create custom instances
  • Set the log level via consola.level or the CONSOLA_LEVEL environment variable
  • Create scoped loggers with consola.withTag("http") for module-specific output
  • Register custom reporters with consola.setReporters() for log aggregation
  • Use consola.wrapConsole() to redirect all console.* calls through Consola

Key Features

  • Isomorphic: works identically in Node.js, Deno, Bun, and browsers
  • Built-in prompt utilities for interactive CLI applications
  • Mockable via consola.mockTypes() for testing log output
  • Pause and resume logging with consola.pause() and consola.resume()
  • Tree-shakeable ESM exports with TypeScript definitions included

Comparison with Similar Tools

  • Winston — a full logging framework with transports; Consola focuses on console output and developer experience
  • Pino — optimized for JSON log output and production throughput; Consola is optimized for human-readable terminal output
  • debug — namespace-based debug logging; Consola provides structured levels and richer formatting
  • Loguru (Python) — similar philosophy of making logging enjoyable; Consola is the JavaScript equivalent

FAQ

Q: Can I use Consola in production? A: Yes. Set the level to control verbosity and use a custom reporter to ship logs to your aggregation service.

Q: Does it support JSON output? A: You can write a custom reporter that serializes log objects to JSON. The default reporters produce human-readable text.

Q: How does it handle errors? A: consola.error() formats Error objects with stack traces. consola.fatal() does the same and signals a non-recoverable state.

Q: Can I disable colors? A: Yes. Set the NO_COLOR or FORCE_COLOR environment variables, or pass colorize: false in reporter options.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires