Nitro
@uloki/nitro — Loki logging plugin for Nitro server
Drop-in Loki logging for Nitro — the server engine that powers Nuxt.
Installation
pnpm add @uloki/nitroSetup
Add the plugin to your nitro.config.ts:
// nitro.config.ts
import { nitroLokiPlugin } from "@uloki/nitro";
export default defineNitroConfig({
plugins: [
nitroLokiPlugin({
endpoint: "http://localhost:3100",
labels: { app: "my-api", env: "production" },
batchSize: 10,
flushInterval: 5000,
}),
],
});How It Works
The plugin hooks into Nitro's build and runtime lifecycle:
- Build time — Injects a virtual runtime module and configuration
- Request hook — Creates a
LokiLoggerper request context - Close hook — Flushes remaining entries on shutdown
- Dev mode — Emits
loki:logevents for playground introspection
Runtime API
// Available in request context
event.context.loki.log({ line: "Custom log", labels: { level: "info" } });
await event.context.loki.flush();Configuration
All standard configuration options are supported:
nitroLokiPlugin({
endpoint: "http://loki:3100", // Loki push endpoint
labels: { app: "my-api" }, // Default labels
enabled: true, // Enable/disable
batchSize: 10, // Entries per batch
flushInterval: 5000, // Auto-flush interval (ms)
redact: ["token", /Bearer\s+\S+/g], // Redaction patterns
})Request Logging
HTTP requests are automatically logged with:
method,path,status,duration_ms- Labels:
method,status,level(info/warn/error)
method=GET path=/api/users status=200 duration_ms=12