Skip to content
CIVersionSizeTypeScriptDependencies
Logit logo

Logit

⚡ Quick Reference

Package: @vielzeug/logit  ·  Category: Logging

Key exports: createLogger

When to use: Structured browser/Node logging with log levels, namespaced scopes, timing helpers, and optional remote transport.

Related: Fetchit · Eventit · Workit

@vielzeug/logit is a zero-dependency logger that augments the native console with level filtering, namespace scopes, styled badges, and optional remote forwarding.

Installation

sh
pnpm add @vielzeug/logit
sh
npm install @vielzeug/logit
sh
yarn add @vielzeug/logit

Quick Start

ts
import { createLogger, Logit } from '@vielzeug/logit';

Logit.info('Boot complete');
Logit.warn('Cache stale');
Logit.fatal(new Error('unrecoverable')); // auto-serializes Error

const api = Logit.scope('api');
api.info({ method: 'GET', path: '/users' }, 'request');

// pin fields to every call — ideal for per-request context
const reqLog = api.withBindings({ requestId: 'abc-123' });
reqLog.info('processing');

const workerLog = createLogger({ logLevel: 'warn', namespace: 'worker' });

await workerLog.groupCollapsed('Job', async () => {
  await workerLog.time('process', () => runJob());
  workerLog.info('Done');
});

Why Logit?

Plain console.log lacks structure: no log levels, no namespacing, no remote delivery, no way to silence logs in production.

ts
// Before — manual approach
if (process.env.NODE_ENV !== 'production') {
  console.log('[api] GET /users', data);
}
fetch('/api/logs', { method: 'POST', body: JSON.stringify({ level: 'error', msg }) });

// After — Logit
import { Logit } from '@vielzeug/logit';
const api = Logit.scope('api');
api.info({ data }, 'GET /users'); // filtered by log level, styled, optionally remote
FeatureLogitWinstonPinoconsole
Bundle size2.1 KB~44 kB~4 kB0 kB
Browser support
Scoped loggersManualChild
Remote logging✅ Built-in✅ Transports✅ Streams
Styled output✅ CSS badgesText onlyText onlyManual
Zero dependencies❌ (15+)❌ (5+)N/A

Use Logit when you need isomorphic logging (browser + Node.js), namespaced module loggers, or remote error delivery without a heavy dependency chain.

Consider alternatives when you need high-throughput file-based logging (Pino), file rotation (Winston), or your team already uses a logging framework.

Features

  • Level filtering (debug to off) with enabled() checks, including fatal above error
  • Structured call signature: log.info('msg'), log.info({ key }, 'msg'), log.error(new Error())
  • Auto-serializes Error objects into { message, name, stack } — survives JSON.stringify
  • Pinned context bindings via withBindings({ requestId }) — fields on every line
  • Namespace composition (scope) and isolated clones (child)
  • Styled browser output (symbol, icon, text)
  • time(), group(), and groupCollapsed() wrappers that auto-close on throw/reject
  • Structured remote payload: { level, message, context, env, namespace?, timestamp? }
  • Non-blocking remote forwarding with separate remote level threshold
  • Zero dependencies — 2.1 KB gzipped

Compatibility

EnvironmentSupport
Browser
Node.js
SSR
Deno

Documentation

See Also