tslog provides pretty console logging by default and optional flat JSON for pipelines. It runs on Node.js, browsers, Deno, Bun, workers, and React Native with zero runtime dependencies.
Overview
tslog is a logging library for TypeScript and JavaScript projects that targets both human-readable development output and structured production logs. The default mode prints colorized pretty lines on an interactive terminal and switches to plain text when output is piped or running in CI. Setting type to json emits fields-first records suited to log aggregators.
Version five reorganized settings into groups, adopted ESM-only publishing, and added middleware, pluggable transports, sub-loggers with inherited configuration, secret masking via keys paths and regex, and stack traces with source-mapped call sites when enabled. Tree-shakeable subpaths cover slim bundles, testing helpers, and optional transports.
The same package adapts to Node.js, Deno, Bun, browser consoles, web workers, and React Native with runtime detection and appropriate defaults. Features include bindings for correlation fields, flush and disposal hooks, custom log levels, and presets aligned with OpenTelemetry and GenAI logging patterns mentioned in docs.
Comparison material in the project positions tslog as a single install that covers browser and server, masking, and pretty or JSON output without requiring separate companion packages for basic workflows.
Key features
- Pretty and JSON output modes
- Zero runtime dependencies
- Secret masking and redaction
- Sub-loggers with inheritance
- Pluggable transports and middleware
- Source-mapped stack locations
- Browser and React Native support
- Tree-shakeable slim build
Use cases
- Structured logs in Node services
- Browser app debugging
- PII-safe JSON logging
- Agent and LLM correlation fields
- Lightweight edge worker logging