Installation

Get started with Vestig in your project.

Install the Core Package

bash
# Bun (recommended)
bun add vestig

# npm
npm install vestig

# pnpm
pnpm add vestig

# Yarn
yarn add vestig

For Next.js Projects

If you're using Next.js 15+, also install the integration package:

bash
bun add @vestig/next

Basic Usage

Import and start logging immediately:

typescript
import { log } from 'vestig'

// Simple messages
log.info('Application started')
log.debug('Loading configuration')
log.warn('Deprecated API called')
log.error('Request failed')

// With metadata
log.info('User action', {
  userId: 'usr_123',
  action: 'purchase',
  amount: 99.99
})

// With errors
try {
  await fetchData()
} catch (error) {
  log.error('Failed to fetch data', error)
}

Log Levels

Vestig supports 5 log levels, from most to least verbose:

LevelValueMethodUse Case
trace10log.trace()Very detailed debugging, performance tracing
debug20log.debug()Development debugging, variable inspection
info30log.info()General information, user actions
warn40log.warn()Warnings, deprecations, potential issues
error50log.error()Errors, exceptions, failures

Environment Configuration

Vestig can be configured via environment variables:

bash
# Set minimum log level
VESTIG_LEVEL=debug

# Enable/disable logging
VESTIG_ENABLED=true

# Enable structured JSON output (auto in production)
VESTIG_STRUCTURED=true

# Enable PII sanitization
VESTIG_SANITIZE=true

# Choose sanitization preset
VESTIG_SANITIZE_PRESET=gdpr  # none, minimal, default, gdpr, hipaa, pci-dss

# Add static context
VESTIG_CONTEXT_SERVICE=api
VESTIG_CONTEXT_VERSION=1.0.0

Custom Logger Instance

For more control, create a custom logger:

typescript
import { createLogger, ConsoleTransport, HTTPTransport } from 'vestig'

const logger = createLogger({
  level: 'debug',
  structured: true,
  sanitize: 'gdpr',  // Use GDPR preset
  context: {
    service: 'api',
    environment: process.env.NODE_ENV
  },
  transports: [
    new ConsoleTransport({ colors: true }),
    new HTTPTransport({
      endpoint: 'https://logs.example.com/ingest',
      batchSize: 100
    })
  ]
})

export { logger }

TypeScript Support

Vestig is written in TypeScript and exports all types:

typescript
import type {
  Logger,
  LoggerConfig,
  LogLevel,
  LogEntry,
  Transport,
  SanitizePreset,
  Span,
  SpanOptions
} from 'vestig'

const config: LoggerConfig = {
  level: 'info',
  structured: true,
  sanitize: 'hipaa'
}

Runtime Detection

Vestig automatically detects your runtime environment:

typescript
import { RUNTIME, CAPABILITIES, IS_SERVER, IS_EDGE } from 'vestig'

console.log(RUNTIME)      // 'node' | 'bun' | 'deno' | 'edge' | 'browser'
console.log(IS_SERVER)    // true in Node/Bun/Deno/Edge, false in browser
console.log(IS_EDGE)      // true in Edge Runtime (Vercel Edge, Cloudflare)

console.log(CAPABILITIES)
// {
//   hasAsyncLocalStorage: true,
//   hasConsole: true,
//   hasProcess: true,
//   hasPerformance: true,
//   hasCrypto: true
// }

Next Steps