or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

console-integration.mdcore-logging.mdindex.mdinstance-management.mdprompts.mdreporters.mdutilities.md
tile.json

index.mddocs/

Consola

Consola is an elegant console logging library that provides sophisticated logging functionality for both Node.js and browser environments. It features multiple log levels, fancy colored output with Unicode support, pluggable reporter system for custom log formatting, interactive prompt support, and comprehensive console/stdout redirection capabilities.

Package Information

  • Package Name: consola
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install consola

Core Imports

For Node.js environments:

import { consola, createConsola } from "consola";

For browser environments:

import { consola, createConsola } from "consola/browser";

For basic functionality only:

import { consola, createConsola } from "consola/basic";

Core functionality without defaults:

import { createConsola } from "consola/core";

Utility functions:

import { 
  box, 
  colors, 
  getColor, 
  colorize,
  formatTree, 
  stripAnsi, 
  centerAlign, 
  rightAlign, 
  leftAlign, 
  align 
} from "consola/utils";

CommonJS:

const { consola, createConsola } = require("consola");

Basic Usage

import { consola } from "consola";

// Basic logging at different levels
consola.info("Application started");
consola.success("Operation completed successfully");
consola.warn("This is a warning message");
consola.error("Something went wrong");
consola.debug("Debug information");

// Tagged logging
const logger = consola.withTag("api");
logger.info("API request received");

// Formatted box messages
consola.box("Important Notice", "This is a highlighted message");

// Interactive prompts
const name = await consola.prompt("What's your name?");
const confirmed = await consola.prompt("Continue?", { type: "confirm" });

Architecture

Consola is built around several key components:

  • Consola Instance: Core logger class with configurable options and pluggable reporters
  • Log Levels: 14 different log levels from silent (-1) to verbose (Infinity)
  • Reporter System: Pluggable output formatters (Basic, Fancy, Browser)
  • Prompt System: Interactive CLI prompts powered by clack
  • Utility Functions: Box drawing, colors, string formatting, and tree structures
  • Environment Detection: Automatic configuration based on execution context

Capabilities

Core Logging

Primary logging functionality with multiple levels, tagging, and custom formatting. Supports all standard log levels plus specialized types like success, fail, ready, start, and box.

interface LogFn {
  (message: InputLogObject | any, ...args: any[]): void;
  raw: (...args: any[]) => void;
}

interface ConsolaInstance {
  // Standard log methods with raw variants
  silent: LogFn;
  fatal: LogFn;
  error: LogFn;
  warn: LogFn;
  log: LogFn;
  info: LogFn;
  success: LogFn;
  fail: LogFn;
  ready: LogFn;
  start: LogFn;
  box: LogFn;
  debug: LogFn;
  trace: LogFn;
  verbose: LogFn;
}

function createConsola(options?: Partial<ConsolaOptions>): ConsolaInstance;

Core Logging

Instance Management

Logger instance creation, configuration, and scoping functionality. Enables creating multiple logger instances with different configurations and tagged scopes.

interface ConsolaInstance {
  create(options: Partial<ConsolaOptions>): ConsolaInstance;
  withDefaults(defaults: InputLogObject): ConsolaInstance;
  withTag(tag: string): ConsolaInstance;
}

Instance Management

Reporter System

Customizable output formatting system with built-in reporters for different environments and extensible reporter interface for custom implementations.

interface ConsolaReporter {
  log(logObj: LogObject, ctx: { options: ConsolaOptions }): void;
}

interface ConsolaInstance {
  addReporter(reporter: ConsolaReporter): ConsolaInstance;
  removeReporter(reporter?: ConsolaReporter): ConsolaInstance;
  setReporters(reporters: ConsolaReporter[]): ConsolaInstance;
  // Level management
  level: LogLevel;
}

Reporters

Interactive Prompts

Interactive command-line prompts with support for text input, confirmation, selection, and multi-selection using clack prompts.

interface ConsolaInstance {
  prompt<T extends PromptOptions = TextPromptOptions>(
    message: string, 
    opts?: T
  ): Promise<inferPromptReturnType<T> | inferPromptCancelReturnType<T>>;
}

type PromptOptions = TextPromptOptions | ConfirmPromptOptions | SelectPromptOptions | MultiSelectOptions;

Prompts

Console Integration

Console and standard stream wrapping/mocking functionality for testing and output redirection. Supports pausing/resuming logs and mocking log methods.

interface ConsolaInstance {
  wrapAll(): void;
  restoreAll(): void;
  wrapConsole(): void;
  restoreConsole(): void;
  wrapStd(): void;
  restoreStd(): void;
  pauseLogs(): void;
  resumeLogs(): void;
  mockTypes(mockFn?: ConsolaOptions["mockFn"]): void;
}

Console Integration

Utility Functions

Formatting and display utilities including box drawing, color functions, string alignment, and tree structure rendering.

function box(text: string, opts?: BoxOpts): string;
function formatTree(items: TreeItem[], options?: TreeOptions): string;
function getColor(color: ColorName, fallback?: ColorName): ColorFunction;

Utilities

Types

interface ConsolaOptions {
  reporters: ConsolaReporter[];
  types: Record<LogType, InputLogObject>;
  level: LogLevel;
  defaults: InputLogObject;
  throttle: number;
  throttleMin: number;
  stdout?: NodeJS.WriteStream;
  stderr?: NodeJS.WriteStream;
  mockFn?: (type: LogType, defaults: InputLogObject) => (...args: any) => void;
  prompt?: typeof import("./prompt").prompt | undefined;
  formatOptions: FormatOptions;
}

interface InputLogObject {
  level?: LogLevel;
  tag?: string;
  type?: LogType;
  message?: string;
  additional?: string | string[];
  args?: any[];
  date?: Date;
}

interface LogObject extends InputLogObject {
  level: LogLevel;
  type: LogType;
  tag: string;
  args: any[];
  date: Date;
  [key: string]: unknown;
}

interface FormatOptions {
  columns?: number;
  date?: boolean;
  colors?: boolean;
  compact?: boolean | number;
  errorLevel?: number;
  [key: string]: unknown;
}

type LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | (number & {});
type LogType = "silent" | "fatal" | "error" | "warn" | "log" | "info" | "success" | "fail" | "ready" | "start" | "box" | "debug" | "trace" | "verbose";