Vite Plugin
The evlog/vite plugin adds build-time DX features to any Vite-based project. It works with SvelteKit, Hono, Express, Fastify, Elysia, and any framework using Vite as its build tool.
evlog/nuxt module via strip and sourceLocation options. You don't need to install the Vite plugin separately.Quick Start
1. Install
bun add evlog
2. Add to vite.config.ts
import { defineConfig } from 'vite'
import evlog from 'evlog/vite'
export default defineConfig({
plugins: [
evlog({
service: 'my-api',
environment: 'production',
}),
],
})
That's it. The plugin automatically:
- Initializes the logger at compile time (no
initLogger()call needed) - Strips
log.debug()calls from production builds
Features
Auto-initialization
The plugin injects logger configuration at compile time via Vite's define hook. Your code can use log, createLogger(), and createRequestLogger() immediately — no initLogger() call required.
// Before (manual setup)
import { initLogger, createLogger } from 'evlog'
initLogger({ env: { service: 'my-api' } })
const log = createLogger()
// After (with Vite plugin)
import { createLogger } from 'evlog'
const log = createLogger()
The service, environment, pretty, silent, enabled, and sampling options are serialized and injected at build time.
Debug stripping
By default, all log.debug() calls are removed from production builds. This is a compile-time transformation — the calls are completely eliminated from the output, not just silenced.
evlog({
service: 'my-api',
// Default: strip debug logs in production builds
// strip: ['debug'],
// Strip debug and info in production:
// strip: ['debug', 'info'],
// Disable stripping:
// strip: [],
})
Stripping only activates during vite build (not vite dev).
Source location injection
When enabled, the plugin injects __source: 'file:line' into object-form log calls. This tells you exactly which file and line produced each log entry.
evlog({
service: 'my-api',
sourceLocation: true, // Always inject
// sourceLocation: 'dev', // Only in development
})
Before transform:
log.info({ action: 'checkout', total: 99 })
After transform:
log.info({ action: 'checkout', total: 99, __source: 'src/checkout.ts:42' })
Auto-imports (opt-in)
Automatically detect and import evlog symbols (log, createEvlogError, parseError, etc.) without manual import statements. Disabled by default.
evlog({
service: 'my-api',
autoImports: true,
})
When enabled, the plugin:
- Scans your code for evlog symbols
- Adds the correct
importstatements automatically - Generates a
.d.tsfile for TypeScript support
createEvlogError, not createError. This avoids conflicts with framework-native createError (Nuxt, Nitro, h3). The standalone createError from evlog is still available via explicit import.Client-side injection
When the client option is provided, the plugin injects a <script> tag into HTML pages that initializes the client-side logger. This enables log.info(), log.error(), etc. in browser code.
evlog({
service: 'my-api',
client: {
console: false,
transport: {
enabled: true,
endpoint: '/api/_evlog/ingest',
},
},
})
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
service | string | 'app' | Service name in logs |
environment | string | Auto-detected | Environment name |
pretty | boolean | true in dev | Pretty print logs |
silent | boolean | false | Suppress console output |
enabled | boolean | true | Enable/disable all logging |
strip | LogLevel[] | ['debug'] | Log levels to remove from production builds |
sourceLocation | boolean | 'dev' | false | Inject source file:line into log calls |
autoImports | boolean | false | Auto-import evlog symbols |
client | object | — | Client-side injection config (console, transport) |
sampling | object | — | Head/tail sampling rates |
Nuxt Integration
The Nuxt module exposes strip and sourceLocation directly in nuxt.config.ts:
export default defineNuxtConfig({
modules: ['evlog/nuxt'],
evlog: {
env: { service: 'my-app' },
strip: ['debug'], // Default
sourceLocation: 'dev', // Inject in dev only
},
})
Vite Compatibility
The plugin supports Vite 7+ and is optimized for Vite 8 (Rolldown). On Vite 8, transform hooks use Rolldown-native filter and moduleType for maximum performance — non-matching files are skipped entirely on the Rust side without crossing the JS bridge.
Wide Events
Learn how to design effective wide events that capture everything you need in a single log. One comprehensive event per request with full context.
AI SDK Integration
Capture token usage, tool calls, model info, and streaming metrics from the Vercel AI SDK into wide events. Wrap your model and get full AI observability.