UNPKG

@fjell/logging

Version:
61 lines (60 loc) 2.37 kB
/** * Correlation ID support for request tracing * Provides utilities for generating and propagating correlation IDs through log entries */ import { Logger, TimeLogger } from './Logger'; /** * Generate a unique correlation ID * Format: timestamp-random (e.g., "lq2x5k-abc123") * @returns A unique correlation ID string */ export declare function generateCorrelationId(): string; /** * Logger wrapper that automatically includes a correlation ID in all log messages * Useful for tracing requests through distributed systems */ export declare class CorrelatedLogger implements Logger { private baseLogger; private correlationId; /** * Create a new CorrelatedLogger * @param baseLogger - The underlying logger to wrap * @param correlationId - Optional correlation ID (generates one if not provided) */ constructor(baseLogger: Logger, correlationId?: string); /** * Format a message with the correlation ID prefix */ private formatWithCorrelation; /** * Get the current correlation ID * @returns The correlation ID for this logger */ getCorrelationId(): string; /** * Create a new CorrelatedLogger with a different correlation ID * @param id - The new correlation ID to use * @returns A new CorrelatedLogger with the specified correlation ID */ withCorrelationId(id: string): CorrelatedLogger; emergency(message: string, ...data: any[]): void; alert(message: string, ...data: any[]): void; critical(message: string, ...data: any[]): void; error(message: string, ...data: any[]): void; warning(message: string, ...data: any[]): void; notice(message: string, ...data: any[]): void; info(message: string, ...data: any[]): void; debug(message: string, ...data: any[]): void; trace(message: string, ...data: any[]): void; default(message: string, ...data: any[]): void; time(message: string, ...data: any[]): TimeLogger; get(...additionalComponents: string[]): Logger; destroy(): void; } /** * Create a correlated logger from an existing logger * @param logger - The base logger to wrap * @param correlationId - Optional correlation ID (generates one if not provided) * @returns A new CorrelatedLogger */ export declare function createCorrelatedLogger(logger: Logger, correlationId?: string): CorrelatedLogger;