@neoma/logging
Version:
Great logging for NestJs
41 lines (40 loc) • 1.85 kB
TypeScript
import { LoggingConfiguration } from "@lib/interfaces";
import { ApplicationLoggerService } from "@lib/services";
/**
* Request-scoped logging service that automatically includes request context.
*
* This service extends ApplicationLoggerService and automatically merges the current
* HTTP request object into the log context. Each request gets its own instance of
* this logger, ensuring request-specific context is always included.
*
* @remarks
* - Request-scoped: New instance created for each HTTP request
* - Automatically includes request details (method, URL, headers, etc.)
* - Generates unique ULID requestTraceId for request correlation
* - Supports extracting trace IDs from request headers with case-insensitive lookup
* - Auto-generates ULID fallback when configured header is missing
* - Logs warning when configured header is not found
* - Merges with application-level logContext from configuration
* - Inherits all logging capabilities from ApplicationLoggerService
*
* @example
* ```typescript
* // Inject into controllers/services
* constructor(private logger: RequestLoggerService) {}
*
* // Every log will include application context, request context, and trace ID
* this.logger.log('User authenticated')
* // Includes: logContext (service, version), requestTraceId, req (method, URL, headers)
* this.logger.error('Validation failed', { field: 'email' })
* // Includes: logContext, requestTraceId, req, plus the field parameter
* ```
*/
export declare class RequestLoggerService extends ApplicationLoggerService {
/**
* Creates an instance of RequestLoggerService.
*
* @param options - Logging configuration from LoggingModule.forRoot()
* @param req - The current HTTP request object (injected by NestJS)
*/
constructor(options: LoggingConfiguration, req: any);
}