Registry / devops / nest-request-postgres-logger

nest-request-postgres-logger

JSON →
library3.0.7jsnpmunverified

A NestJS module that logs HTTP request data to the terminal and persists requests/logs to a PostgreSQL database using MikroORM. Version 3.0.7, actively maintained, requires nestjs-cls for request context and @mikro-orm/core/postgresql/migrations v5.6.15+. Differentiators: hides secrets, customizable headers, attaches user/custom data, uses dedicated 'nlogger' schema, optionally supports papertrail syslog transport.

npm install nest-request-postgres-logger
INSTALL
IMPORT
SIG · NEST-REQUEST-POSTG
N
nest-request-postgres-logger
devopsjavascriptv3.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

NLoggerModule
import { NLoggerModule } from 'nest-request-postgres-logger'
const NLoggerModule = require('nest-request-postgres-logger').NLoggerModule
ESM only; CommonJS require is unsupported (package is type: module)
NLogger
import { NLogger } from 'nest-request-postgres-logger'
import NLogger from 'nest-request-postgres-logger'
Named export, not default. Used to replace NestJS built-in logger.
NLoggerOptions
import type { NLoggerOptions } from 'nest-request-postgres-logger'
import { NLoggerOptions } from 'nest-request-postgres-logger'
TypeScript type only; use type import to avoid runtime side effects.

Shows basic setup: import NLoggerModule with Postgres config in AppModule, replace default NestJS logger with NLogger in main.ts.

// app.module.ts import { Module } from '@nestjs/common'; import { ClsModule } from 'nestjs-cls'; import { NLoggerModule } from 'nest-request-postgres-logger'; import { AppController } from './app.controller'; @Module({ imports: [ ClsModule.forRoot({ global: true, middleware: { mount: true } }), NLoggerModule.forRoot({ dbConfig: { host: process.env.DB_HOST ?? 'localhost', port: Number(process.env.DB_PORT ?? 5432), dbName: process.env.DB_NAME ?? 'postgres', user: process.env.DB_USER ?? 'postgres', password: process.env.DB_PASSWORD ?? '', }, headers: ['user-agent', 'content-type', 'x-request-id'], hiddenProperties: ['password', 'token', 'secret'], }), ], controllers: [AppController], }) export class AppModule {} // main.ts import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { NLogger } from 'nest-request-postgres-logger'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.useLogger(app.get(NLogger)); await app.listen(3000); } bootstrap();
Debug
Known issues
breakingRequires nestjs-cls v3.2.1+ with ClsModule.forRoot({ middleware: { mount: true } }). Missing this will cause logger to not capture request context.
fix
Add ClsModule.forRoot({ global: true, middleware: { mount: true } }) to imports.
affects: >=3.0.0
gotchaThe logger uses a dedicated 'nlogger' database schema. MikroORM schema generation (e.g., during migrations) may try to drop it unless explicitly ignored.
fix
Set schemaGenerator.ignoreSchema: ['nlogger'] in MikroORM configuration.
affects: >=1.0.0
deprecatedThe 'NLogger' class replaces the NestJS logger. Failure to call app.useLogger(app.get(NLogger)) will result in default NestJS logging instead of this module's behavior.
fix
In main.ts, after creating the app, call app.useLogger(app.get(NLogger)).
affects: >=3.0.0
gotchaHeaders config defaults to ['user-agent', 'content-type'] only. Other headers like 'authorization' are not logged unless explicitly added.
fix
Include desired headers in the 'headers' array during module configuration.
affects: >=3.0.0
breakingMinimum peer dependency: @nestjs/common ^10.3.0, MikroORM ^5.6.15. Older NestJS or MikroORM versions cause runtime errors.
fix
Upgrade @nestjs/common to >=10.3.0 and MikroORM packages to ^5.6.15.
affects: 3.0.0
Errors
Common errors & fixes
Cannot find module 'nest-request-postgres-logger'
Package not installed or missing peer dependencies.
fix
Run: npm install nestjs-cls @mikro-orm/core @mikro-orm/postgresql @mikro-orm/migrations nest-request-postgres-logger
Nest cannot resolve dependencies of the NLogger (...). Please make sure that the argument ClsService at index [0] is available in the current context.
ClsModule is not imported or configured incorrectly.
fix
Add ClsModule.forRoot({ global: true, middleware: { mount: true } }) to the imports array of your root module.
Column path in where clause is ambiguous: nlogger_request.id
Custom query joins nlogger tables without table aliases.
fix
Use explicit table aliases in your custom queries (e.g., 'nr.id' instead of 'id').
Upgrade
Version history
3.0.7latest on npm
Audit
Dependencies
@mikro-orm/corerequiredORM for Postgres operations
@mikro-orm/postgresqlrequiredPostgreSQL driver for MikroORM
@mikro-orm/migrationsrequiredSchema migration support
@nestjs/commonrequiredNestJS core decorators and interfaces
nestjs-clsrequiredContinuation-local storage for request context
rxjsrequiredReactive extensions used by NestJS and logger
Agent activity
2 hits · last 30 days
node
2
Resources
nest-request-postgres-logger — npm install nest-request-postgres-logger · libregistry