Gathering detailed insights and metrics for nestjs-pino-batch-http-transport
Gathering detailed insights and metrics for nestjs-pino-batch-http-transport
Gathering detailed insights and metrics for nestjs-pino-batch-http-transport
Gathering detailed insights and metrics for nestjs-pino-batch-http-transport
npm install nestjs-pino-batch-http-transport
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
A NestJS module that configures nestjs-pino
to use a custom Pino transport for batching logs and sending them via HTTP. It uses axios
directly for HTTP requests and pino-abstract-transport
for efficient, out-of-process log handling.
axios
.pino-abstract-transport
.pino-pretty
to the transport pipeline in non-production environments if no other transport is specified by the user.url
: The target HTTP endpoint for logs.batchSize
: Maximum number of logs to send in a single batch (default: 100).batchInterval
: Maximum time in milliseconds to wait before sending a batch (default: 5000).headers
: Static headers to include in every HTTP request (e.g., for API keys).axiosRequestTimeout
: Timeout for the Axios HTTP request in milliseconds (default: 10000).NestJsPinoBatchHttpModule.forRoot()
for static configuration and NestJsPinoBatchHttpModule.forRootAsync()
for dynamic/asynchronous configuration.1npm install nestjs-pino-batch-http-transport 2# or 3yarn add nestjs-pino-batch-http-transport
Ensure you also have nestjs-pino
(and its peer pino-http
) installed as per the nestjs-pino
documentation. If you want to use pino-pretty
in development (which is the default behavior of this module if the batch transport is enabled and no other transport is specified), install it as a dev dependency:
1npm install --save-dev pino-pretty 2# or 3yarn add --dev pino-pretty
Import NestJsPinoBatchHttpModule
into your application's root module. This module configures and provides the necessary options to nestjs-pino
's LoggerModule
internally.
1// app.module.ts 2import { Module } from '@nestjs/common'; 3import { NestJsPinoBatchHttpModule } from 'nestjs-pino-batch-http-transport'; 4 5@Module({ 6 imports: [ 7 NestJsPinoBatchHttpModule.forRoot({ 8 // Optional pino-http options (passed to nestjs-pino) 9 pinoHttp: { 10 level: process.env.NODE_ENV !== 'production' ? 'debug' : 'info', 11 // autoLogging: true, // Other pino-http options 12 }, 13 14 // Configuration for the batch HTTP transport 15 batchTransportConfig: { 16 url: 'YOUR_LOGGING_ENDPOINT_URL', // Required 17 batchSize: 100, // Optional, default: 100 18 batchInterval: 5000, // Optional, default: 5000ms 19 headers: { 'X-API-KEY': 'YOUR_OPTIONAL_API_KEY' }, // Optional 20 axiosRequestTimeout: 10000, // Optional, default: 10000ms 21 }, 22 23 enableTransport: process.env.NODE_ENV === 'production', // Default is false. Set to true for non local environments. 24 enablePinoPretty: process.env.NODE_ENV !== 'production', // Default is true. Set to false for non local environments. 25 }), 26 // ... other modules 27 ], 28}) 29export class AppModule {}
1// app.module.ts 2import { Module } from '@nestjs/common'; 3import { ConfigModule, ConfigService } from '@nestjs/config'; 4import { NestJsPinoBatchHttpModule, BatchHttpTransportConfig } from 'nestjs-pino-batch-http-transport'; 5 6@Module({ 7 imports: [ 8 ConfigModule.forRoot({ isGlobal: true }), // Your ConfigModule setup 9 10 NestJsPinoBatchHttpModule.forRootAsync({ 11 imports: [ConfigModule], // Make ConfigModule available 12 inject: [ConfigService], 13 useFactory: async (configService: ConfigService) => { 14 const batchConfig: BatchHttpTransportConfig = { 15 url: configService.get<string>('LOGGING_ENDPOINT_URL'), 16 batchSize: configService.get<number>('LOGGING_BATCH_SIZE', 100), 17 batchInterval: configService.get<number>('LOGGING_BATCH_INTERVAL_MS', 5000), 18 axiosRequestTimeout: configService.get<number>('LOGGING_AXIOS_TIMEOUT_MS', 10000), 19 headers: { 20 'X-App-Version': configService.get<string>('APP_VERSION', '1.0.0'), 21 'X-API-KEY': configService.get<string>('LOGGING_API_KEY'), 22 }, 23 }; 24 25 return { 26 pinoHttp: { 27 level: configService.get<string>('LOG_LEVEL', 'info'), 28 // Other pino-http options... 29 }, 30 batchTransportConfig: batchConfig, 31 enableTransport: configService.get<boolean>('ENABLE_BATCH_LOGGING', true), 32 }; 33 }, 34 }), 35 // ... other modules 36 ], 37}) 38export class AppModule {}
No vulnerabilities found.
No security vulnerabilities found.