{"id":43411,"library":"nest-request-postgres-logger","title":"NestJS Request Logger with PostgreSQL","description":"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.","status":"active","version":"3.0.7","language":"javascript","source_language":"en","source_url":"https://github.com/skey-network/nest-request-postgres-logger","tags":["javascript","nestjs","logger","logging","postgres","mikro-orm","middleware","typescript"],"install":[{"cmd":"npm install nest-request-postgres-logger","lang":"bash","label":"npm"},{"cmd":"yarn add nest-request-postgres-logger","lang":"bash","label":"yarn"},{"cmd":"pnpm add nest-request-postgres-logger","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"ORM for Postgres operations","package":"@mikro-orm/core","optional":false},{"reason":"PostgreSQL driver for MikroORM","package":"@mikro-orm/postgresql","optional":false},{"reason":"Schema migration support","package":"@mikro-orm/migrations","optional":false},{"reason":"NestJS core decorators and interfaces","package":"@nestjs/common","optional":false},{"reason":"Continuation-local storage for request context","package":"nestjs-cls","optional":false},{"reason":"Reactive extensions used by NestJS and logger","package":"rxjs","optional":false}],"imports":[{"note":"ESM only; CommonJS require is unsupported (package is type: module)","wrong":"const NLoggerModule = require('nest-request-postgres-logger').NLoggerModule","symbol":"NLoggerModule","correct":"import { NLoggerModule } from 'nest-request-postgres-logger'"},{"note":"Named export, not default. Used to replace NestJS built-in logger.","wrong":"import NLogger from 'nest-request-postgres-logger'","symbol":"NLogger","correct":"import { NLogger } from 'nest-request-postgres-logger'"},{"note":"TypeScript type only; use type import to avoid runtime side effects.","wrong":"import { NLoggerOptions } from 'nest-request-postgres-logger'","symbol":"NLoggerOptions","correct":"import type { NLoggerOptions } from 'nest-request-postgres-logger'"}],"quickstart":{"code":"// app.module.ts\nimport { Module } from '@nestjs/common';\nimport { ClsModule } from 'nestjs-cls';\nimport { NLoggerModule } from 'nest-request-postgres-logger';\nimport { AppController } from './app.controller';\n\n@Module({\n  imports: [\n    ClsModule.forRoot({ global: true, middleware: { mount: true } }),\n    NLoggerModule.forRoot({\n      dbConfig: {\n        host: process.env.DB_HOST ?? 'localhost',\n        port: Number(process.env.DB_PORT ?? 5432),\n        dbName: process.env.DB_NAME ?? 'postgres',\n        user: process.env.DB_USER ?? 'postgres',\n        password: process.env.DB_PASSWORD ?? '',\n      },\n      headers: ['user-agent', 'content-type', 'x-request-id'],\n      hiddenProperties: ['password', 'token', 'secret'],\n    }),\n  ],\n  controllers: [AppController],\n})\nexport class AppModule {}\n\n// main.ts\nimport { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module';\nimport { NLogger } from 'nest-request-postgres-logger';\n\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule);\n  app.useLogger(app.get(NLogger));\n  await app.listen(3000);\n}\nbootstrap();","lang":"typescript","description":"Shows basic setup: import NLoggerModule with Postgres config in AppModule, replace default NestJS logger with NLogger in main.ts."},"warnings":[{"fix":"Add ClsModule.forRoot({ global: true, middleware: { mount: true } }) to imports.","message":"Requires nestjs-cls v3.2.1+ with ClsModule.forRoot({ middleware: { mount: true } }). Missing this will cause logger to not capture request context.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Set schemaGenerator.ignoreSchema: ['nlogger'] in MikroORM configuration.","message":"The logger uses a dedicated 'nlogger' database schema. MikroORM schema generation (e.g., during migrations) may try to drop it unless explicitly ignored.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"In main.ts, after creating the app, call app.useLogger(app.get(NLogger)).","message":"The '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.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Include desired headers in the 'headers' array during module configuration.","message":"Headers config defaults to ['user-agent', 'content-type'] only. Other headers like 'authorization' are not logged unless explicitly added.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Upgrade @nestjs/common to >=10.3.0 and MikroORM packages to ^5.6.15.","message":"Minimum peer dependency: @nestjs/common ^10.3.0, MikroORM ^5.6.15. Older NestJS or MikroORM versions cause runtime errors.","severity":"breaking","affected_versions":"3.0.0"}],"env_vars":null,"search_vec":"'/core/postgresql/migrations':41 '3.0.7':27 'activ':28 'attach':48 'cls':33 'context':36 'customiz':46 'data':13,50 'databas':23 'dedic':52 'differenti':43 'header':47 'hide':44 'http':11 'javascript':60 'log':10,63 'logger':3,62 'maintain':29 'middlewar':68 'mikro':39,66 'mikro-orm':38,65 'mikroorm':25 'modul':8 'nestj':1,7,32,61 'nestjs-cl':31 'nlogger':53 'option':55 'orm':40,67 'papertrail':57 'persist':18 'postgr':64 'postgresql':5,22 'request':2,12,35 'requests/logs':19 'requir':30 'schema':54 'secret':45 'support':56 'syslog':58 'termin':16 'transport':59 'typescript':69 'use':24,51 'user/custom':49 'v5.6.15':42 'version':26","created_at":"2026-06-05T16:59:40.263987+00:00","updated_at":"2026-06-05T16:59:40.263987+00:00","problems":[{"fix":"Run: npm install nestjs-cls @mikro-orm/core @mikro-orm/postgresql @mikro-orm/migrations nest-request-postgres-logger","cause":"Package not installed or missing peer dependencies.","error":"Cannot find module 'nest-request-postgres-logger'"},{"fix":"Add ClsModule.forRoot({ global: true, middleware: { mount: true } }) to the imports array of your root module.","cause":"ClsModule is not imported or configured incorrectly.","error":"Nest cannot resolve dependencies of the NLogger (...). Please make sure that the argument ClsService at index [0] is available in the current context."},{"fix":"Use explicit table aliases in your custom queries (e.g., 'nr.id' instead of 'id').","cause":"Custom query joins nlogger tables without table aliases.","error":"Column path in where clause is ambiguous: nlogger_request.id"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/skey-network/nest-request-postgres-logger#readme","github":"https://github.com/skey-network/nest-request-postgres-logger","docs":null,"changelog":null,"pypi":null,"npm":"nest-request-postgres-logger","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}