Primary logging functionality providing 14 different log levels, raw output variants, and flexible message formatting for both simple strings and complex log objects.
Consola provides 14 distinct log levels ranging from silent (-Infinity) to verbose (Infinity), each with specific use cases and default output formatting.
interface ConsolaInstance {
/** Silent logging (level: -Infinity) - no output */
silent(message?: any, ...args: any[]): void;
/** Fatal errors (level: 0) - critical system failures */
fatal(message?: any, ...args: any[]): void;
/** Error logging (level: 0) - standard errors */
error(message?: any, ...args: any[]): void;
/** Warning messages (level: 1) - potential issues */
warn(message?: any, ...args: any[]): void;
/** General logging (level: 2) - standard output */
log(message?: any, ...args: any[]): void;
/** Informational messages (level: 3) - general information */
info(message?: any, ...args: any[]): void;
/** Success messages (level: 3) - operation completed successfully */
success(message?: any, ...args: any[]): void;
/** Failure messages (level: 3) - operation failed */
fail(message?: any, ...args: any[]): void;
/** Ready state messages (level: 3) - system ready */
ready(message?: any, ...args: any[]): void;
/** Start messages (level: 3) - operation starting */
start(message?: any, ...args: any[]): void;
/** Box messages (level: 3) - highlighted important messages */
box(message?: any, ...args: any[]): void;
/** Debug messages (level: 4) - development information */
debug(message?: any, ...args: any[]): void;
/** Trace messages (level: 5) - detailed execution traces */
trace(message?: any, ...args: any[]): void;
/** Verbose messages (level: Infinity) - maximum detail output */
verbose(message?: any, ...args: any[]): void;
}Usage Examples:
import { consola } from "consola";
// Basic string logging
consola.info("Application starting...");
consola.success("Database connected successfully");
consola.warn("Memory usage approaching limit");
consola.error("Failed to connect to API", error);
// Multiple arguments
consola.debug("User data:", userData, "Request ID:", requestId);
// Complex objects
consola.log({
event: "user_login",
userId: 123,
timestamp: new Date()
});Each log method includes a .raw variant that bypasses formatting and outputs arguments directly.
interface LogFn {
(message?: any, ...args: any[]): void;
raw: (...args: any[]) => void;
}
// All log methods extend LogFn, providing both formatted and raw variants
interface ConsolaInstance {
info: LogFn;
error: LogFn;
// ... all other log methods
}Usage Examples:
// Formatted output (default)
consola.info("Processing", count, "items");
// Output: ℹ Processing 10 items
// Raw output
consola.info.raw("Processing", count, "items");
// Output: Processing 10 itemsAdvanced logging using structured log objects with additional metadata and formatting options.
interface InputLogObject {
/** Log level override */
level?: LogLevel;
/** Categorization tag */
tag?: string;
/** Log type override */
type?: LogType;
/** Primary message text */
message?: string;
/** Additional text lines */
additional?: string | string[];
/** Additional arguments */
args?: any[];
/** Custom timestamp */
date?: Date;
/** Custom properties for specialized log types */
[key: string]: unknown;
}Usage Examples:
// Structured logging
consola.info({
message: "User authentication",
tag: "auth",
additional: ["User ID: 123", "Session: abc123"],
level: 3
});
// Box logging with custom styling
consola.box({
message: "System Alert",
title: "Important Notice",
style: {
borderColor: "red",
borderStyle: "double"
}
});Dynamic log level management to control output verbosity.
interface ConsolaInstance {
/** Get current log level */
get level(): LogLevel;
/** Set minimum log level for output */
set level(level: LogLevel);
}
// Log level constants
const LogLevels: Record<LogType, number> = {
silent: Number.NEGATIVE_INFINITY,
fatal: 0,
error: 0,
warn: 1,
log: 2,
info: 3,
success: 3,
fail: 3,
ready: 3,
start: 3,
box: 3,
debug: 4,
trace: 5,
verbose: Number.POSITIVE_INFINITY
};Usage Examples:
// Set log level to show only warnings and errors
consola.level = 1;
// Check current level
if (consola.level >= 4) {
consola.debug("Debug information");
}
// Environment-based level setting
consola.level = process.env.NODE_ENV === "development" ? 4 : 2;Automatic formatting and throttling of log messages to prevent spam and improve readability.
interface ConsolaOptions {
/** Maximum repetitions within throttle window */
throttle: number;
/** Minimum time between identical messages (ms) */
throttleMin: number;
/** Default properties for all log messages */
defaults: InputLogObject;
/** Message formatting options */
formatOptions: FormatOptions;
}
interface FormatOptions {
/** Terminal width for formatting */
columns?: number;
/** Include timestamps */
date?: boolean;
/** Enable color output */
colors?: boolean;
/** Compact output mode */
compact?: boolean | number;
/** Error stack trace depth */
errorLevel?: number;
}Usage Examples:
// Create instance with custom formatting
const logger = createConsola({
formatOptions: {
date: true,
colors: false,
compact: true
},
throttle: 5000, // 5 second throttle window
throttleMin: 3 // Show max 3 identical messages
});
// Spam prevention - identical messages are throttled
for (let i = 0; i < 100; i++) {
logger.info("Repeated message");
}
// Only shows first few instances with "(repeated X times)" summarytype LogLevel = 0 | 1 | 2 | 3 | 4 | 5 | (number & {});
type LogType =
| "silent" | "fatal" | "error" | "warn" | "log" | "info"
| "success" | "fail" | "ready" | "start" | "box"
| "debug" | "trace" | "verbose";
interface LogObject extends InputLogObject {
level: LogLevel;
type: LogType;
tag: string;
args: any[];
date: Date;
[key: string]: unknown;
}