UNPKG

digital-samba-mcp-server

Version:

Digital Samba MCP Server - Model Context Protocol server for Digital Samba's video conferencing API

146 lines 5.3 kB
/** * Logger configuration for Digital Samba MCP Server * * This module configures a Winston logger with console and file transports. * It provides structured logging with timestamps and supports different log levels * that can be configured through the LOG_LEVEL environment variable. * * @module logger * @author Digital Samba Team * @version 0.1.0 */ import winston from 'winston'; /** * Enhanced metadata structure for logging */ export interface LoggingMetadata { instanceId?: string; hostname?: string; nodeVersion?: string; pid?: number; requestId?: string; sessionId?: string; apiKey?: string; operation?: string; component?: string; duration?: number; statusCode?: number; [key: string]: any; } /** * Request context storage for correlating logs within a request lifecycle */ export declare class LogContext { private static requestContext; /** * Initialize a new request context with a unique ID * @param sessionId Optional session ID * @returns Request ID for the new context */ static initRequest(sessionId?: string): string; /** * Get the metadata for a request context * @param requestId Request ID * @returns Metadata object or empty object if not found */ static getContext(requestId: string): LoggingMetadata; /** * Update the metadata for a request context * @param requestId Request ID * @param metadata Metadata to merge with existing context */ static updateContext(requestId: string, metadata: LoggingMetadata): void; /** * Remove a request context when the request is complete * @param requestId Request ID */ static endRequest(requestId: string): void; /** * Create a logger that includes the request context in every log entry * @param requestId Request ID * @returns Logger with request context */ static getContextLogger(requestId: string): { debug: (message: string, metadata?: LoggingMetadata) => void; info: (message: string, metadata?: LoggingMetadata) => void; warn: (message: string, metadata?: LoggingMetadata) => void; error: (message: string, metadata?: LoggingMetadata) => void; }; /** * Create a child logger for a specific component * @param component Component name * @returns Logger with component in metadata */ static getComponentLogger(component: string): { debug: (message: string, metadata?: LoggingMetadata) => void; info: (message: string, metadata?: LoggingMetadata) => void; warn: (message: string, metadata?: LoggingMetadata) => void; error: (message: string, metadata?: LoggingMetadata) => void; }; } /** * Configure and create the Winston logger instance * * The logger uses the following configuration: * - Log level: Configured via LOG_LEVEL environment variable (defaults to 'info') * - Format: JSON with timestamps for file output, colorized simple format for console * - Transports: * - Console: All levels, with colorization * - Error File: Only error level messages in 'error.log' * - Combined File: All levels in 'combined.log' */ declare const logger: winston.Logger; /** * Helper function to create a scoped logger with standard metadata * @param component Component name for categorizing logs * @returns A logger instance with component metadata */ export declare function createComponentLogger(component: string): { debug: (message: string, metadata?: LoggingMetadata) => void; info: (message: string, metadata?: LoggingMetadata) => void; warn: (message: string, metadata?: LoggingMetadata) => void; error: (message: string, metadata?: LoggingMetadata) => void; }; /** * Helper function to log performance metrics * @param operation Operation name * @param startTime Start time in milliseconds * @param metadata Additional metadata */ export declare function logPerformance(operation: string, startTime: number, metadata?: LoggingMetadata): void; /** * The configured logger instance for use throughout the application * * @example * import logger from './logger.js'; * * // Basic logging * logger.debug('Detailed debugging information'); * logger.info('General operational information'); * logger.warn('Warning conditions'); * logger.error('Error conditions', { error: err }); * * // Structured logging with metadata * logger.info('User logged in', { userId: 123, role: 'admin' }); * * // Component-specific logging * import { createComponentLogger } from './logger.js'; * const dbLogger = createComponentLogger('database'); * dbLogger.info('Connected to database', { database: 'users' }); * * // Request-scoped logging * import { LogContext } from './logger.js'; * const requestId = LogContext.initRequest(sessionId); * const reqLogger = LogContext.getContextLogger(requestId); * reqLogger.info('Processing request', { endpoint: '/api/users' }); * // Later when done * LogContext.endRequest(requestId); * * // Performance logging * import { logPerformance } from './logger.js'; * const startTime = Date.now(); * // ... do operation ... * logPerformance('fetch-users', startTime, { count: 10 }); */ export default logger; //# sourceMappingURL=logger.d.ts.map