Scripts2026年7月17日·1 分钟阅读

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.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Consola
直接安装命令
npx -y tokrepo@latest install 4921cf35-81b9-11f1-9bc6-00163e2b0d79 --target codex

先 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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产