Wide event logging plugin for Elysia - structured logging with request context
npm install 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.
- Server Start Log: Log custom data on server startup with start option
- 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-id header
- Performance Metrics: Automatic request duration tracking
``bash`
bun add elysia-wide-event
`typescript
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);
`
See the screenshot above for output examples. Pretty colored output by default, JSON with json: true option.
`typescript`
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) |
Add context to the current request log.
`typescript`
wideEvent.set("auth", { userId: "123", role: "admin" });
Log error details. Accepts any object.
`typescript``
wideEvent.error({ type: "ValidationError", message: "Invalid email" });
wideEvent.error({ code: "E001", reason: "timeout" });
- Bun >= 1.0.0
- Elysia >= 1.0.0
MIT