explaingit

unjs/consola

7,261TypeScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

Consola is a JavaScript logging library for Node.js and the browser that replaces the built-in console with cleaner colored output, configurable log levels, and swappable custom reporters.

Mindmap

mindmap
  root((Consola))
    What it does
      Structured logging
      Multiple log levels
      Colored terminal output
    Features
      Pause and resume logs
      Tag-based tracing
      Mock in tests
    Custom reporters
      File output
      JSON formatting
      Fatal exit handling
    Environments
      Node.js server
      Browser
      CI and test friendly
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Replace scattered console.log calls in a Node.js app with leveled, colored log output that silences itself in CI environments.

USE CASE 2

Write a custom reporter that formats log lines as JSON and sends them to a log aggregation service without changing the rest of your code.

USE CASE 3

Mock all log output during automated tests so that test output stays clean and assertions are not cluttered with debug messages.

Tech stack

TypeScriptJavaScriptNode.js

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

Consola is a logging library for JavaScript applications running in Node.js or the browser. Instead of using the built-in console directly, you route your log calls through Consola, which then formats and displays them in a cleaner way. It works in both server-side and browser environments and ships with a colored, styled output by default, falling back to a simpler format in testing or CI environments where fancy output would be noise. The library supports multiple log levels, from fatal errors down to verbose debug traces. You pick which level is visible at runtime, so a production app might show only warnings and errors while a development session shows everything. Each level has its own method, like consola.info(), consola.warn(), consola.success(), and consola.error(), giving log lines a consistent look without extra formatting code. Beyond basic logging, Consola lets you pause and resume log output, tag log messages with a label so you can trace which part of a system a message came from, and mock all log calls during tests so automated test output stays clean. It also integrates with interactive terminal prompts, letting you ask the user a yes/no question or display a selection menu from the same logger instance. One of its notable design points is the reporter system. By default Consola uses its built-in reporters, but you can swap or add your own. A custom reporter is just an object with a log method, so you could write one that sends logs to a file, formats them as JSON, or exits the process on fatal errors. This makes the library adaptable without requiring changes to the rest of your code. Consola also offers smaller build variants for projects where bundle size matters. You can import from consola/basic or consola/core to skip the fancy terminal styling and reduce the footprint by roughly 80 percent.

Copy-paste prompts

Prompt 1
How do I configure Consola to show only warnings and errors in production but show all debug and verbose messages during local development?
Prompt 2
Write a custom Consola reporter that formats every log entry as a JSON object and appends it to a file called app.log.
Prompt 3
How do I use Consola's interactive prompt feature to ask a user a yes/no confirmation question inside a Node.js command-line tool?
Open on GitHub → Explain another repo

← unjs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.