logceptor
TypeScript icon, indicating that this package has built-in type declarations

1.0.19 • Public • Published

logceptor

NestJS interceptor to log HTTP requests and responses with full control, correlation IDs, file rotation, sensitive data masking, and production-ready features for traceability, compliance, and debugging.


✨ Features

  • ✅ Log levels (log, warn, error, debug)
  • ✅ JSON or plain-text format
  • ✅ Sensitive field masking (e.g. password, token, ssn)
  • ✅ Correlation ID (auto-generated UUID or incoming x-correlation-id header)
  • ✅ File size-based log rotation (default 10MB, configurable)
  • ✅ Automatically deletes logs older than 30 days
  • ✅ Configurable output folder and filename

📦 Installation

npm install logceptor

🚀 Usage (Global Interceptor)

Add the following to your NestJS main.ts:

// ✅ Public usage (npm installed)
import { LoggingInterceptor } from 'logceptor';

// 🔄 Optional: if you're testing a local version before publishing
// import { LoggingInterceptor } from '@mobilefirst/logger';

app.useGlobalInterceptors(new LoggingInterceptor({
  format: 'json',                      // Log format: 'json' or 'text'
  level: 'debug',                      // Log level: 'log' | 'debug' | 'warn' | 'error'
  folder: 'logs',                      // Output directory for logs
  filename: 'access.log',              // File name
  maskFields: ['password', 'token', 'ssn'], // Fields to mask
  maxFileSizeMB: 10                    // Max file size before rotation (default: 10)
}));

🧪 Output Example (logs/access.log)

{"type":"request","timestamp":"2025-06-24T12:00:00Z","correlationId":"a3009ffe-430f-4481-ba55-eec7e6be9b44","method":"POST","url":"/api/users/login","body":{"email":"a@b.com","password":"****"}}
{"type":"response","timestamp":"2025-06-24T12:00:00Z","correlationId":"a3009ffe-430f-4481-ba55-eec7e6be9b44","url":"/api/users/login","duration":"31ms","response":{"message":"Logged in"}}

🧹 Automatic Log Cleanup

  • Logs are saved in the defined folder (e.g. logs/)
  • Files older than 30 days are automatically deleted

👤 Author

Created by Mehul JadavMobileFirst


📝 License

MIT © Mobilefirst Applications

Package Sidebar

Install

npm i logceptor

Weekly Downloads

38

Version

1.0.19

License

MIT

Unpacked Size

26 kB

Total Files

11

Last publish

Collaborators

  • mehuljadav