Getting Started

Introduction

A structured logging library for TypeScript. Simple logging, wide events, and structured errors — from quick one-liners to comprehensive request-scoped events.

evlog is a structured logging library for TypeScript. It gives you simple one-liner logs, wide events that accumulate context over any operation, and structured errors that explain why something failed and how to fix it.

Inspired by Logging Sucks by Boris Tane.

Philosophy

Traditional logging is broken. Your logs are scattered across dozens of files. Each request generates 10+ log lines. When something goes wrong, you're left grep-ing through noise hoping to find signal.

evlog takes a different approach:

Structured Logging

Replace console.log with typed, structured events that flow through a drain pipeline.

Wide Events

Accumulate context over any unit of work — a request, script, or job — and emit once.

Structured Errors

Errors that explain why they occurred and how to fix them.

Pretty for Dev

Human-readable in development, machine-parseable JSON in production.

Three Ways to Log

evlog provides three APIs for different contexts. You can use all three in the same project.

Simple Logging

Fire-and-forget structured logs. Replace console.log, consola, or pino:

src/index.ts
import { log } from 'evlog'

log.info('auth', 'User logged in')
log.error({ action: 'payment', error: 'card_declined', userId: 42 })

Wide Events

Accumulate context progressively over any operation, then emit a single comprehensive event:

import { createLogger } from 'evlog'

const log = createLogger({ jobId: 'sync-001', queue: 'emails' })
log.set({ batch: { size: 50, processed: 50 } })
log.emit()

One log, all context. Everything you need to understand what happened.

Structured Errors

Errors with actionable context — why it happened, how to fix it, and a link to docs:

import { createError } from 'evlog'

throw createError({
  message: 'Payment failed',
  status: 402,
  why: 'Card declined by issuer (insufficient funds)',
  fix: 'Try a different payment method or contact your bank',
  link: 'https://docs.example.com/payments/declined',
})

Why Context Matters

We're entering an era where AI agents build, debug, and maintain applications. These agents need structured context to work effectively:

  • why: The root cause, so the agent understands what went wrong
  • fix: An actionable solution the agent can suggest or apply
  • link: Documentation for complex issues

Traditional console.log and generic throw new Error() provide no actionable context. evlog's structured output is designed for both humans and AI to parse and act on.

Next Steps