Skip to content

Console LoggerJavaScript Logger for Browser & Node.js

Structured, namespaced console logging with child loggers, beautiful terminal output, and flexible transports — TypeScript-first, zero dependencies, ~10 KB.

Console Logger

A console logger that works everywhere

Console Logger is a TypeScript-first JavaScript logger built for both browser and Node.js. It replaces console.log with structured, namespaced logging — six numeric log levels (trace, debug, info, warn, error, fatal), child loggers that carry request context, beautiful ANSI terminal output, browser DevTools styling, redaction, and pluggable transports (HTTP, file, stream).

Where most loggers force you to pick a side — Pino, Winston, and Bunyan are Node-only, while loglevel and debug are browser-only — Console Logger is one library that runs in both. Same API. Same JSON schema. Auto-detects the environment and picks the right format: pretty ANSI in a TTY, NDJSON in CI, styled %c badges in the browser console.

ts
import { Konsole } from 'konsole-logger';

const log = new Konsole({ namespace: 'App' });

log.info('Server started', { port: 3000 });   // INF [App] Server started port=3000
log.warn('Slow query', { ms: 812, sql });      // WRN [App] Slow query ms=812 sql=...
log.error(new Error('DB unreachable'));        // ERR [App] DB unreachable

const req = log.child({ requestId: 'r_42' });  // attaches requestId to every line
req.debug('Cache miss');                        // DBG [App] Cache miss requestId=r_42
🌐

Browser & Node.js

Same API on both. Auto-picks ANSI, NDJSON, or DevTools.

🏷️

Child loggers

child({ requestId }) attaches context to every line.

📊

Structured JSON

Pino-compatible schema with six numeric levels.

⏱️

Timestamps

ISO, epoch, custom, or nanosecond — switchable at runtime.

🔒

Redaction

Mask passwords & PII with dot-notation paths.

🚚

Transports

HTTP batching, file rotation + gzip, streams.

🧵

Worker mode

Off-main-thread storage and HTTP batching.

📦

TypeScript-first

Full types, zero runtime dependencies.

~10 KB gzipped

On par with Pino; smaller than Winston and Bunyan.

Code Snippets

Six numeric log levels — discard everything below your threshold.

const logger = new Konsole({
  namespace: 'App',
  level: 'info',    // trace + debug discarded
});

logger.trace('→ entering loop');   // 10 — dropped
logger.debug('Cache miss');         // 20 — dropped
logger.info('Server started', { port: 3000 }); // 30 ✅
logger.warn('Memory at 80%');       // 40 ✅
logger.error(new Error('timeout')); // 50 ✅
logger.fatal('Out of memory');      // 60 ✅

Usage Examples

Console has no framework dependency — it works everywhere: React, plain HTML, and Node.js servers.

Import as a module in any React app — works with Next.js, Vite, and CRA.

import { Konsole } from 'konsole-logger';

// Create loggers at module level
const logger = new Konsole({ namespace: 'App', format: 'silent' });
const api    = new Konsole({ namespace: 'API', level: 'warn' });

function Dashboard() {
  const handleClick = () => {
    const req = logger.child({ requestId: crypto.randomUUID() });
    req.info('Dashboard loaded', { userId: 42 });
  };

  return <button onClick={handleClick}>Load</button>;
}

// Expose for DevTools debugging
Konsole.exposeToWindow();

Benchmarks

Measured on Apple M5 Max, Node.js v24.15, 100K iterations. Pino, Winston, and Bunyan are Node.js only; Consola runs in the browser but without worker offloading. Console runs in both with worker offloading. Run npm run benchmark to reproduce.

Production throughput — emitting structured JSON to a stream (the path that runs in real apps; higher is better)

Loggerops/secp50
Console4.16M125 ns
Consola795.9K1.13 µs
Bunyan741.8K1.25 µs
Winston672.9K917 ns
Pino560.5K1.63 µs

Disabled / silent — microbenchmark for per-call overhead (not a realistic throughput; nobody ships silenced loggers)

ModeConsolePinoConsolaWinston
Silent / disabled13.45M13.57M15.24M2.98M
Child (silent / disabled)32.86M34.02M22.60M2.12M

Console, Pino, and Consola are within run-to-run V8 noise on the silent path — the gap shows up where it matters: actually emitting log lines.

Browser-only

ScenarioConsole
Silent + buffer6.01M
With Workernon-blocking

Bundle & install size (smaller is better)

ConsolePinoWinstonBunyanConsola
Bundle (gzip)~10 KB~32 KB~70 KB~45 KB~12 KB
Install size135 KB1.17 MB360 KB212 KB420 KB
Dependencies0111100

See the Performance Guide for details.