elysia-wide-event
v0.1.3
Published
Wide event logging plugin for Elysia - structured logging with request context
Maintainers
Readme
elysia-wide-event
Wide event logging plugin for Elysia. Aggregates all request context into a single structured log line for better observability.
Inspired by Logging Sucks - the wide event pattern that makes debugging actually enjoyable.

Bun + Elysia only. This plugin is designed specifically for the Bun runtime and Elysia framework. Node.js is not supported.
Features
- Server Start Log: Log custom data on server startup with
startoption - Context Accumulation: Collect data throughout request lifecycle via
wideEvent.set() - Flexible Output: Pretty colored output or JSON - you choose
- Request ID: Auto-generates or extracts from
x-request-idheader - Performance Metrics: Automatic request duration tracking
Installation
bun add elysia-wide-eventQuick Start
import { Elysia } from "elysia";
import { wideEvent } from "elysia-wide-event";
const app = new Elysia()
.use(wideEvent())
.post("/users", ({ wideEvent, body }) => {
wideEvent.set("user", { email: body.email });
const userId = "abc-123";
wideEvent.set("result", { userId });
return { success: true };
})
.listen(3000);Output
See the screenshot above for output examples. Pretty colored output by default, JSON with json: true option.
Options
wideEvent({
generateRequestId: () => crypto.randomUUID(),
requestIdHeader: "x-request-id",
json: false,
start: { env: "production", version: "1.0.0" },
});| Option | Type | Default | Description |
| ------------------- | -------------- | ------------------- | ----------------------------------------------------- |
| generateRequestId | () => string | crypto.randomUUID | Custom request ID generator |
| requestIdHeader | string | "x-request-id" | Header for incoming request ID |
| json | boolean | false | Output as JSON instead of pretty format |
| start | LogData | undefined | Custom data to log on server startup (URL auto-added) |
API
wideEvent.set(key, data)
Add context to the current request log.
wideEvent.set("auth", { userId: "123", role: "admin" });wideEvent.error(data)
Log error details. Accepts any object.
wideEvent.error({ type: "ValidationError", message: "Invalid email" });
wideEvent.error({ code: "E001", reason: "timeout" });Requirements
- Bun >= 1.0.0
- Elysia >= 1.0.0
License
MIT
