NestJS
Import from @blyp/core/nestjs.
Required bootstrap order
Call createLogger() before NestFactory.create(...).
import "reflect-metadata";
import { Module, Controller, Get, Req } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { logger } from "@blyp/core";
import { createLogger, BlypModule } from "@blyp/core/nestjs";
@Controller()
class AppController {
@Get("/hello")
hello(@Req() request: { blypLog?: { info(message: string): void } }) {
request.blypLog?.info("nest-request");
logger.info("nest-route");
return { ok: true };
}
}
@Module({
imports: [BlypModule.forRoot()],
controllers: [AppController],
})
class AppModule {}
createLogger({
level: "info",
clientLogging: true,
});
const app = await NestFactory.create(AppModule);
await app.listen(3000);What BlypModule does
- applies middleware to all routes
- registers a global interceptor
- registers a global exception filter
- supports both Nest Express and Nest Fastify adapters
If you call BlypModule.forRoot() before createLogger(...), Blyp throws an initialization error during bootstrap.
What auto-logged requests look like
With automatic request logging enabled, Blyp emits terminal output like:
[INFO] GET /health 200 2ms
[INFO] POST /checkout 200 143ms
[INFO] GET /users/42 404 8ms
[ERROR] POST /payments 500 1203msFields included automatically: method, path, status code, and duration.
In production (NDJSON):
{"level":"info","time":1710000000000,"msg":"GET /health","type":"http_request","method":"GET","url":"/health","statusCode":200,"responseTime":2}
{"level":"info","time":1710000000001,"msg":"POST /checkout","type":"http_request","method":"POST","url":"/checkout","statusCode":200,"responseTime":143}Relevant types
import type {
NestLoggerConfig,
NestLoggerContext,
NestAdapterType,
} from "@blyp/core/nestjs";