{"id":30656284,"url":"https://github.com/dongitran/nestjs-mongodb-logger","last_synced_at":"2026-01-20T16:58:03.008Z","repository":{"id":311439799,"uuid":"1043618395","full_name":"dongitran/nestjs-mongodb-logger","owner":"dongitran","description":"📜 A fast and reliable MongoDB 🍃 logger for NestJS 🐈, built for production workloads.","archived":false,"fork":false,"pushed_at":"2025-08-25T02:08:50.000Z","size":483,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-01T16:26:23.165Z","etag":null,"topics":["logger","logging","mongodb","nestjs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dongitran.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-24T08:51:23.000Z","updated_at":"2025-08-25T02:08:53.000Z","dependencies_parsed_at":"2025-08-24T18:35:54.379Z","dependency_job_id":"b8f7d779-f5f2-473a-8446-6b44a4fdcffe","html_url":"https://github.com/dongitran/nestjs-mongodb-logger","commit_stats":null,"previous_names":["dongitran/nestjs-mongodb-logger"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dongitran/nestjs-mongodb-logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongitran%2Fnestjs-mongodb-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongitran%2Fnestjs-mongodb-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongitran%2Fnestjs-mongodb-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongitran%2Fnestjs-mongodb-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dongitran","download_url":"https://codeload.github.com/dongitran/nestjs-mongodb-logger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dongitran%2Fnestjs-mongodb-logger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001448,"owners_count":26083078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["logger","logging","mongodb","nestjs","typescript"],"created_at":"2025-08-31T10:44:04.039Z","updated_at":"2025-10-09T12:17:31.948Z","avatar_url":"https://github.com/dongitran.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 NestJS MongoDB Logger\n\nA production-ready MongoDB logging package for NestJS applications, featuring optimized batch processing and robust connection management.\n\n[![CI](https://github.com/dongitran/nestjs-mongodb-logger/actions/workflows/ci.yml/badge.svg)](https://github.com/dongitran/nestjs-mongodb-logger/actions/workflows/ci.yml)\n\n## ✨ Features\n\n- **🔌 Reliable Connection**: Auto-reconnects with exponential backoff and connection pooling.\n- **⚡ Optimized Batching**: Logs are batched and flushed based on size or time intervals to reduce database load.\n- **🧩 Seamless NestJS Integration**: Simple setup with `forRoot` and `forRootAsync`.\n- **🩺 Health Monitoring**: Includes a `HealthCheckService` to monitor the connection and batch processing status.\n- **🕵️ Automatic Logging**: Provides a `LogInterceptor` to automatically log method calls, arguments, and results.\n\n## 📊 Data Flow\n\n```mermaid\ngraph TD\n    A[Your Application] --\u003e|\"Calls logger.log()\"| B(MongoLoggerService);\n    B --\u003e|\"Adds to queue\"| C{BatchManager};\n    C --\u003e|\"Flushes batch (on size/time)\"| D[ConnectionManager];\n    D --\u003e|\"Writes to DB\"| E((MongoDB));\n```\n\n## 📦 Installation\n\n```bash\npnpm install nestjs-mongodb-logger\n```\n\n## 🚀 Quick Start\n\n**1. Import the module:**\n\n```typescript\n// app.module.ts\nimport { Module } from '@nestjs/common';\nimport { MongoLoggerModule } from 'nestjs-mongodb-logger';\n\n@Module({\n  imports: [\n    MongoLoggerModule.forRoot({\n      uri: 'your-mongodb-connection-string',\n      defaultCollection: 'app-logs',\n      batchSize: 100,       // Optional: Default is 500\n      flushInterval: 5000,  // Optional: Default is 5000ms\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n**2. Inject and use the service:**\n\n```typescript\n// any.service.ts\nimport { Injectable } from '@nestjs/common';\nimport { MongoLoggerService } from 'nestjs-mongodb-logger';\n\n@Injectable()\nexport class MyService {\n  constructor(private readonly logger: MongoLoggerService) {}\n\n  doSomething() {\n    this.logger.log('my-logs', {\n      level: 'info',\n      message: 'User performed an action',\n      metadata: { userId: '123', context: 'Billing' }\n    });\n  }\n\n  handleError(error: Error) {\n    this.logger.logError('error-logs', error, { context: 'MyService' });\n  }\n}\n```\n\n## ⚙️ Asynchronous Configuration\n\nUse `forRootAsync` to configure the module with environment variables.\n\n```typescript\n// app.module.ts\nimport { ConfigModule, ConfigService } from '@nestjs/config';\nimport { MongoLoggerModule } from 'nestjs-mongodb-logger';\n\n@Module({\n  imports: [\n    ConfigModule.forRoot(),\n    MongoLoggerModule.forRootAsync({\n      imports: [ConfigModule],\n      useFactory: async (configService: ConfigService) =\u003e ({\n        uri: configService.get\u003cstring\u003e('MONGO_URI'),\n      }),\n      inject: [ConfigService],\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n## 👨‍💻 Author\n\ndongtran ✨\n\n---\n\nMade with ❤️ to make your work life easier!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdongitran%2Fnestjs-mongodb-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdongitran%2Fnestjs-mongodb-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdongitran%2Fnestjs-mongodb-logger/lists"}