UNPKG

ds-sfcoe-ailabs

Version:

AI-powered code review tool with static analysis integration for comprehensive code quality assessment.

188 lines (187 loc) 6 kB
import winston from 'winston'; import type { DatadogLoggerConfig } from '../../utils/index.js'; /** * Datadog Winston logger configuration and setup * Provides a wrapper around Winston logger with Datadog transport integration * Supports both console and Datadog HTTP transports with fallback mechanisms * * @example * ```typescript * // Initialize the logger * const config = { * apiKey: 'your-datadog-api-key', * service: 'my-service', * environment: 'production' * }; * DatadogLogger.initialize(config); * * // Use logging methods * DatadogLogger.info('Application started', { version: '1.0.0' }); * DatadogLogger.error('Database error', new Error('Connection failed')); * ``` */ export declare class DatadogLogger { private static instance; private static config; /** * Initialize the Datadog logger with configuration * * @param config - The Datadog logger configuration object * @returns The initialized Winston logger instance * @example * ```typescript * const config = { * apiKey: 'dd-api-key', * service: 'ai-pr-review', * environment: 'production', * logLevel: 'info' * }; * const logger = DatadogLogger.initialize(config); * ``` */ static initialize(config: DatadogLoggerConfig): winston.Logger; /** * Get the configured logger instance * * @returns The Winston logger instance * @throws Error if logger is not initialized * @example * ```typescript * try { * const logger = DatadogLogger.getInstance(); * logger.info('Direct Winston usage'); * } catch (error) { * console.error('Logger not initialized'); * } * ``` */ static getInstance(): winston.Logger; /** * Check if logger is initialized * * @returns True if the logger is initialized, false otherwise * @example * ```typescript * if (!DatadogLogger.isInitialized()) { * DatadogLogger.initialize(config); * } * ``` */ static isInitialized(): boolean; /** * Get current configuration * * @returns The current Datadog logger configuration or null if not set * @example * ```typescript * const config = DatadogLogger.getConfig(); * if (config) { * console.log(`Service: ${config.service}`); * } * ``` */ static getConfig(): DatadogLoggerConfig | null; /** * Log debug message * * @param message - The debug message to log * @param meta - Optional metadata object to include with the log * @example * ```typescript * DatadogLogger.debug('Debug information', { userId: '123', action: 'validate' }); * ``` */ static debug(message: string, meta?: Record<string, unknown>): void; /** * Log info message * * @param message - The info message to log * @param meta - Optional metadata object to include with the log * @example * ```typescript * DatadogLogger.info('User logged in', { userId: '123', sessionId: 'abc' }); * ``` */ static info(message: string, meta?: Record<string, unknown>): void; /** * Log warning message * * @param message - The warning message to log * @param meta - Optional metadata object to include with the log * @example * ```typescript * DatadogLogger.warn('Rate limit approaching', { currentRate: 90, limit: 100 }); * ``` */ static warn(message: string, meta?: Record<string, unknown>): void; /** * Log error message * * @param message - The error message to log * @param error - Optional error object or metadata to include with the log * @example * ```typescript * DatadogLogger.error('Database connection failed', new Error('Timeout')); * DatadogLogger.error('Validation failed', { field: 'email', value: 'invalid' }); * ``` */ static error(message: string, error?: Error | Record<string, unknown>): void; /** * Log with custom level * * @param level - The log level (e.g., 'info', 'debug', 'error') * @param message - The message to log * @param meta - Optional metadata object to include with the log * @example * ```typescript * DatadogLogger.log('info', 'Custom log entry', { customField: 'value' }); * DatadogLogger.log('debug', 'Debug information', debugData); * ``` */ static log(level: string, message: string, meta?: Record<string, unknown>): void; /** * Update custom metadata that will be included in all future logs * * @param meta - The metadata object to merge with existing custom metadata * @example * ```typescript * DatadogLogger.updateCustomMeta({ userId: '123', sessionId: 'abc' }); * // All subsequent logs will include this metadata * ``` */ static updateCustomMeta(meta: Record<string, unknown>): void; /** * Set a specific metadata field * * @param key - The metadata field key * @param value - The value to set for the metadata field * @example * ```typescript * DatadogLogger.setMetaField('userId', '123'); * DatadogLogger.setMetaField('feature', 'pr-review'); * ``` */ static setMetaField(key: string, value: unknown): void; /** * Remove a metadata field * * @param key - The metadata field key to remove * @example * ```typescript * DatadogLogger.removeMetaField('temporaryField'); * // Future logs will not include this field * ``` */ static removeMetaField(key: string): void; /** * Get current custom metadata * * @returns The current custom metadata object * @example * ```typescript * const currentMeta = DatadogLogger.getCustomMeta(); * console.log('Current metadata:', currentMeta); * ``` */ static getCustomMeta(): Record<string, unknown>; }