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
pnpm add evlog
bun add evlog
yarn add evlog
npm install 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
The plugin transforms your source at build time — log.debug() calls are deleted from the output, __source: 'file:line' is injected into object-form log calls, and initLogger() is wired in via Vite's define hook so you never have to call it yourself.
Auto-initialization
The plugin injects logger configuration at compile time via Vite's define hook. The service, environment, pretty, silent, enabled, and sampling options are serialized and injected at build time, so log, createLogger(), and createRequestLogger() work immediately without an initLogger() call.
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 so you know exactly which file and line produced each log entry.
evlog({
service: 'my-api',
sourceLocation: true, // Always inject
// sourceLocation: 'dev', // Only in development
})
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.
Performance
evlog adds ~3µs per request. Faster than pino, consola, and winston in most scenarios while emitting richer, more useful events.
Auto-Redaction
Automatically scrub PII from wide events before console output and drains. Built-in smart masking for credit cards, emails, IPs, phone numbers, JWTs, and more.