Database Logging
Use database logging when your deployment cannot rely on local file persistence, especially in serverless environments.
Database mode changes Blyp's primary sink from files to your database. Connectors such as Better Stack, PostHog, Sentry, and OTLP continue to work independently.
Requirements
- set
destination: "database" - use an executable config file such as
blyp.config.ts - provide a Prisma or Drizzle adapter at runtime
blyp.config.json alone is not enough for this mode because adapters are runtime objects.
Supported setups
- Prisma + Postgres
- Prisma + MySQL
- Drizzle + Postgres
- Drizzle + MySQL
CLI setup available: You can scaffold the schema, run migrations, and generate
blyp.config.tsautomatically usingblyp db:init. See the CLI docs for the guided setup flow.
Prisma example
import { PrismaClient } from "@prisma/client";
import { createPrismaDatabaseAdapter } from "@blyp/core/database";
const prisma = new PrismaClient();
export default {
destination: "database",
database: {
dialect: "postgres",
adapter: createPrismaDatabaseAdapter({
client: prisma,
model: "blypLog",
}),
},
};Drizzle example
import { createDrizzleDatabaseAdapter } from "@blyp/core/database";
import { db } from "./db";
import { blypLogs } from "./db/schema/blyp";
export default {
destination: "database",
database: {
dialect: "mysql",
adapter: createDrizzleDatabaseAdapter({
db,
table: blypLogs,
}),
},
};Delivery behavior
The database delivery queue supports immediate writes and batched writes.
Default values:
strategy: "immediate"batchSize: 1flushIntervalMs: 250maxQueueSize: 1000overflowStrategy: "drop-oldest"flushTimeoutMs: 5000retry.maxRetries: 1retry.backoffMs: 100
export default {
destination: "database",
database: {
dialect: "postgres",
adapter,
delivery: {
strategy: "batch",
batchSize: 50,
flushIntervalMs: 1000,
},
},
};Flushing and shutdown
All Blyp loggers expose:
await logger.flush();
await logger.shutdown();Promise-based integrations such as Elysia, Hono, Next.js, SvelteKit, and TanStack Start flush automatically in database mode before the request completes.
For callback-style servers such as Express, Fastify, and NestJS, call await logger.flush() at your own boundary when you need a hard durability point.
CLI-assisted setup
As of CLI v0.1.3, the recommended setup flow is:
blyp db:init
blyp db:migrate
blyp db:generatedb:generate is only needed for Prisma projects.
Without a global install:
bunx @blyp/cli db:init
bunx @blyp/cli db:migrate
bunx @blyp/cli db:generateImport paths
Use:
@blyp/core/databasefor adapter factories and database-specific types@blyp/corefor config helpers such asresolveConfig()andResolvedBlypConfig