{"_id":"@bluealba/nestjs-pino","name":"@bluealba/nestjs-pino","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@bluealba/nestjs-pino","version":"1.0.0","description":"NestJS pino based logger module including pino-http","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","lint":"biome check","lint:fix":"biome check --write","test":"jest","test:watch":"jest --watch","test:coverage":"jest --coverage"},"keywords":["pino","nestjs","logger"],"author":{"name":"Blue Alba"},"license":"PolyForm-Noncommercial-1.0.0","dependencies":{"nestjs-pino":"^4.5.0","typescript":"^5.9.3"},"peerDependencies":{"@nestjs/common":"^10.0.0 || ^11.0.0","reflect-metadata":"^0.1.13 || ^0.2.0"},"devDependencies":{"@nestjs/common":"^11.1.9","@nestjs/testing":"^11.1.9","@types/jest":"^30.0.0","biome":"^0.3.3","jest":"^30.2.0","reflect-metadata":"^0.2.2","ts-jest":"^29.4.6"},"publishConfig":{"@bluealba:registry":"https://registry.npmjs.org/","access":"public"},"_id":"@bluealba/nestjs-pino@1.0.0","gitHead":"b003ac03797fc2d2bd344fbdf681ac0ee0062aa1","_nodeVersion":"22.22.0","_npmVersion":"10.9.4","dist":{"integrity":"sha512-gQcGui7Rtvbpy3imSwohsR6L+z1u5i2kUqP7iKVHkZdgBo65sdRE9OxqJp0O7FP/HXjq4Gpwn29GYj9LETBY7Q==","shasum":"6aec29d56b5c81a02092cde6f410cc93752478cb","tarball":"https://registry.npmjs.org/@bluealba/nestjs-pino/-/nestjs-pino-1.0.0.tgz","fileCount":18,"unpackedSize":23767,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGPIQElkt/iCWJtSGx/V+FnV5l1xV2utSTM2HFSzWbdhAiBo/E/5BJw4783lrjkxoCE4n9cOmtOJoCGbPvtMWXG1MQ=="}]},"_npmUser":{"name":"bluealba","email":"npm@bluealba.com"},"directories":{},"maintainers":[{"name":"bluealba","email":"npm@bluealba.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/nestjs-pino_1.0.0_1769177076329_0.09930031831616604"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-23T14:04:36.217Z","1.0.0":"2026-01-23T14:04:36.485Z","modified":"2026-01-23T14:04:36.670Z"},"maintainers":[{"name":"bluealba","email":"npm@bluealba.com"}],"description":"NestJS pino based logger module including pino-http","keywords":["pino","nestjs","logger"],"author":{"name":"Blue Alba"},"license":"PolyForm-Noncommercial-1.0.0","readme":"# @bluealba/nestjs-pino\n\nA NestJS logger module built on top of [nestjs-pino](https://github.com/iamolegga/nestjs-pino) with opinionated defaults for production-ready logging using Pino and pino-http.\n\n## Features\n\n- High-performance JSON logging with Pino\n- HTTP request/response logging with pino-http\n- Automatic logger context based on the injecting class\n- Buffered asynchronous logging for optimal performance\n- Automatic redaction of sensitive headers\n- Global module - import once, use everywhere\n\n## Installation\n\n```bash\nnpm install @bluealba/nestjs-pino\n```\n\n## Usage\n\n### 1. Import the LoggerModule\n\nImport `LoggerModule` in your application's root module:\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { LoggerModule } from '@bluealba/nestjs-pino';\n\n@Module({\n  imports: [LoggerModule],\n  // ...\n})\nexport class AppModule {}\n```\n\nSince `LoggerModule` is a global module, you only need to import it once in your root module. It will be available throughout your entire application.\n\n### 2. Inject the Logger\n\n**Important**: The logger must be injected via dependency injection. Inject the `Logger` into any service, controller, or provider:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { Logger } from '@bluealba/nestjs-pino';\n\n@Injectable()\nexport class UserService {\n  constructor(private readonly logger: Logger) {}\n\n  async findUser(id: string) {\n    this.logger.info({ userId: id }, 'Finding user');\n    // ...\n  }\n}\n```\n\n### 3. Automatic Context Setting\n\nThe logger context is **automatically set** based on the class where it's injected. You do **not** need to call `setContext()` manually.\n\n```typescript\n@Injectable()\nexport class UserService {\n  constructor(private readonly logger: Logger) {\n    // Context is automatically set to \"UserService\"\n    // No need to call: this.logger.setContext('UserService')\n  }\n\n  createUser(data: CreateUserDto) {\n    // Logs will include: \"context\": \"UserService\"\n    this.logger.info({ data }, 'Creating user');\n  }\n}\n```\n\nThe context is derived from the class constructor name, making it easy to identify which part of your application generated each log entry.\n\n### 4. Logging Methods\n\nThe logger provides all standard Pino logging methods:\n\n```typescript\nthis.logger.trace('Trace message');\nthis.logger.debug({ data }, 'Debug message');\nthis.logger.info({ userId: '123' }, 'Info message');\nthis.logger.warn('Warning message');\nthis.logger.error({ err }, 'Error message');\nthis.logger.fatal('Fatal message');\n```\n\nThe `log()` method is also available and maps to `info()`:\n\n```typescript\nthis.logger.log('This is an info message');\n```\n\n## Default Configuration\n\nThis library comes with production-ready defaults:\n\n### Logging Performance\n\n- **Asynchronous logging**: Logs are written asynchronously to avoid blocking the event loop\n- **Buffering**:\n  - Minimum buffer length: 512 bytes\n  - Maximum buffer length: 128 KB\n  - Maximum write size: 128 KB\n- **Periodic flush**: Every 1000ms (1 second)\n\n### Security\n\nSensitive HTTP headers are automatically redacted from logs:\n- `req.headers.authorization`\n- `req.headers.cookie`\n\n### Request Serialization\n\nHTTP requests are logged with the following fields:\n- `id`: Request ID\n- `method`: HTTP method\n- `url`: Request URL\n- `headers`: Request headers (with sensitive data redacted)\n- `remoteAddress`: Client IP address\n- `remotePort`: Client port or X-Forwarded-Port header\n\n### Timestamp Format\n\nLogs include a Unix timestamp (milliseconds since epoch):\n```json\n{\n  \"level\": 30,\n  \"timestamp\": 1705761234567,\n  \"context\": \"UserService\",\n  \"msg\": \"User created\"\n}\n```\n\n## Why Use This Library?\n\nThis library wraps `nestjs-pino` with sensible defaults so you don't have to configure:\n- Buffering and async logging for performance\n- Security best practices (header redaction)\n- Structured request logging\n- Context management\n\nIt allows you to focus on writing logs instead of configuring the logger.\n\n## License\n\nPolyForm-Noncommercial-1.0.0\n","readmeFilename":"README.md","_rev":"1-ae47a9a5c9857008b09f2d2cdc1ca743"}