Oleqlog

Examples

Raw OleqLog recipes for NestJS, Next.js, and Express

These examples use OleqLog directly. For official middleware, modules, and hooks, see Adapters.

StackWhere to initWhen to flush
NestJSInjectable provider or module bootstraponModuleDestroy / shutdown hook
Next.jsRoute Handler or server actionEnd of request / after()
ExpressApp bootstrapSIGTERM handler

Never expose OLEQLOG_API_KEY in browser code. Log from your server (API routes, workers, Nest providers).


NestJS

Module + provider

oleq-log.module.ts
import { Global, Inject, Module, OnModuleDestroy } from "@nestjs/common";
import OleqLog from "@oleq-ai/logs";

export const OLEQ_LOG = Symbol("OLEQ_LOG");

@Global()
@Module({
  providers: [
    {
      provide: OLEQ_LOG,
      useFactory: () =>
        new OleqLog({
          appName: "api",
          environment: process.env.NODE_ENV ?? "development",
        }),
    },
  ],
  exports: [OLEQ_LOG],
})
export class OleqLogModule implements OnModuleDestroy {
  constructor(@Inject(OLEQ_LOG) private readonly log: OleqLog) {}

  async onModuleDestroy() {
    await this.log.flush();
    await this.log.close();
  }
}

Prefer the built-in module: NestJS adapter.


Next.js

App Router Route Handler — init once per cold start:

app/api/health/route.ts
import OleqLog from "@oleq-ai/logs";

const log = new OleqLog({ appName: "web" });

export async function GET() {
  await log.info({ message: "health check" });
  await log.flush();
  return Response.json({ ok: true });
}

For lazy init and client logging, see Next.js adapters.


Express

server.ts
import express from "express";
import OleqLog from "@oleq-ai/logs";

const app = express();
const log = new OleqLog({ appName: "api" });

app.use((req, res, next) => {
  const start = Date.now();
  res.on("finish", () => {
    void log.info({
      message: `${req.method} ${req.originalUrl}`,
      kind: "res",
      body: { status: res.statusCode, ms: Date.now() - start },
    });
  });
  next();
});

process.on("SIGTERM", async () => {
  await log.flush();
  await log.close();
  process.exit(0);
});

Or use Express adapter middleware instead.

See also: Pino transport

On this page