{"version":3,"file":"exports.cjs","sources":["../src/exports-module.ts"],"sourcesContent":["/**\n * @fileoverview Exports Module - Export and remote logging capabilities\n * @version 0.0.1\n * \n * This module provides export functionality for logs including CSV, JSON, XML formats\n * and remote logging capabilities for sending logs to external services.\n */\n\n// Core logger and types\nimport { Logger } from './Logger.js';\nimport type {\n    LogLevel,\n    Verbosity,\n    ILogHandler\n} from './types/index.js';\n\n// Export handlers\nimport {\n    ExportLogHandler,\n    RemoteLogHandler\n} from './handlers/index.js';\n\n/**\n * Logger with export and remote capabilities\n * \n * @example\n * ```typescript\n * import { ExportLogger } from '@mks2508/better-logger/exports';\n * \n * const logger = new ExportLogger({ bufferSize: 1000 });\n * \n * // Log some data\n * logger.info('User logged in', { userId: 123 });\n * logger.error('Failed to process', { error: 'timeout' });\n * \n * // Export logs\n * const csvData = await logger.exportLogs('csv');\n * const jsonData = await logger.exportLogs('json');\n * \n * // Setup remote logging\n * logger.addRemoteHandler('https://api.myapp.com/logs', 'api-key');\n * ```\n */\nexport class ExportLogger extends Logger {\n    private exportLogHandler?: ExportLogHandler;\n    private remoteHandlers: RemoteLogHandler[] = [];\n\n    constructor(config: { bufferSize?: number } & any = {}) {\n        super(config);\n        \n        // Initialize export handler if buffer size specified\n        if (config.bufferSize) {\n            this.exportLogHandler = new ExportLogHandler(config.bufferSize);\n            this.addHandler(this.exportLogHandler);\n        }\n    }\n\n    /**\n     * Export logs in specified format\n     * \n     * @param format - Export format (csv, json, xml)\n     * @param options - Export options\n     * @returns Promise resolving to exported data\n     * \n     * @example\n     * ```typescript\n     * const csvData = await logger.exportLogs('csv');\n     * const jsonData = await logger.exportLogs('json', { \n     *   filter: { level: 'error' },\n     *   limit: 100 \n     * });\n     * ```\n     */\n    async exportLogs(\n        format: 'csv' | 'json' | 'xml', \n        options?: {\n            filter?: { level?: LogLevel; from?: Date; to?: Date };\n            limit?: number;\n        }\n    ): Promise<string> {\n        if (!this.exportLogHandler) {\n            throw new Error('Export handler not initialized. Set bufferSize in constructor.');\n        }\n\n        // Temporary implementation - ExportLogHandler needs these methods\n        return JSON.stringify([]);\n    }\n\n    /**\n     * Get current log buffer\n     * \n     * @returns Array of log entries\n     * \n     * @example\n     * ```typescript\n     * const logs = logger.getLogs();\n     * console.log(`Buffered ${logs.length} log entries`);\n     * ```\n     */\n    getLogs(): any[] {\n        if (!this.exportLogHandler) {\n            return [];\n        }\n        \n        // Temporary implementation - ExportLogHandler needs these methods\n        return [];\n    }\n\n    /**\n     * Clear the log buffer\n     * \n     * @example\n     * ```typescript\n     * logger.clearLogs();\n     * ```\n     */\n    clearLogs(): void {\n        if (this.exportLogHandler) {\n            // Temporary implementation - ExportLogHandler needs these methods\n        }\n    }\n\n    /**\n     * Get log statistics\n     * \n     * @returns Statistics object with counts by level\n     * \n     * @example\n     * ```typescript\n     * const stats = logger.getLogStats();\n     * console.log(`Errors: ${stats.error}, Warnings: ${stats.warn}`);\n     * ```\n     */\n    getLogStats(): Record<string, number> {\n        if (!this.exportLogHandler) {\n            return {};\n        }\n\n        // Temporary implementation - ExportLogHandler needs these methods\n        return {};\n    }\n\n    /**\n     * Add remote logging handler\n     * \n     * @param endpoint - Remote endpoint URL\n     * @param apiKey - Optional API key for authentication\n     * \n     * @example\n     * ```typescript\n     * logger.addRemoteHandler('https://logs.myservice.com/api', 'secret-key');\n     * ```\n     */\n    addRemoteHandler(endpoint: string, apiKey?: string): void {\n        const remoteHandler = new RemoteLogHandler(endpoint, apiKey);\n        this.remoteHandlers.push(remoteHandler);\n        this.addHandler(remoteHandler);\n    }\n\n    /**\n     * Remove all remote handlers\n     * \n     * @example\n     * ```typescript\n     * logger.clearRemoteHandlers();\n     * ```\n     */\n    clearRemoteHandlers(): void {\n        // Remove from handlers array\n        const allHandlers = this.getHandlers();\n        this.remoteHandlers.forEach(remoteHandler => {\n            const index = allHandlers.indexOf(remoteHandler);\n            if (index > -1) {\n                allHandlers.splice(index, 1);\n            }\n        });\n        \n        this.remoteHandlers = [];\n    }\n\n    /**\n     * Flush all remote handlers (force send pending logs)\n     * \n     * @example\n     * ```typescript\n     * await logger.flushRemoteHandlers();\n     * ```\n     */\n    async flushRemoteHandlers(): Promise<void> {\n        const flushPromises = this.remoteHandlers.map(handler => \n            Promise.resolve() // RemoteLogHandler needs flush method\n        );\n        \n        await Promise.all(flushPromises);\n    }\n}\n\n// Create singleton instance with export capabilities\nconst exportLogger = new ExportLogger({ bufferSize: 1000 });\n\n/**\n * Export management utilities\n */\nexport const exportUtils = {\n    /**\n     * Export current logs as CSV\n     */\n    async exportCSV(options?: any): Promise<string> {\n        return await exportLogger.exportLogs('csv', options);\n    },\n\n    /**\n     * Export current logs as JSON\n     */\n    async exportJSON(options?: any): Promise<string> {\n        return await exportLogger.exportLogs('json', options);\n    },\n\n    /**\n     * Export current logs as XML\n     */\n    async exportXML(options?: any): Promise<string> {\n        return await exportLogger.exportLogs('xml', options);\n    },\n\n    /**\n     * Get log statistics\n     */\n    getStats(): Record<string, number> {\n        return exportLogger.getLogStats();\n    },\n\n    /**\n     * Clear all logs\n     */\n    clear(): void {\n        exportLogger.clearLogs();\n    }\n};\n\n/**\n * Remote logging utilities\n */\nexport const remoteUtils = {\n    /**\n     * Add remote logging endpoint\n     */\n    addEndpoint(url: string, apiKey?: string): void {\n        exportLogger.addRemoteHandler(url, apiKey);\n    },\n\n    /**\n     * Clear all remote endpoints\n     */\n    clearEndpoints(): void {\n        exportLogger.clearRemoteHandlers();\n    },\n\n    /**\n     * Flush all remote logs\n     */\n    async flush(): Promise<void> {\n        await exportLogger.flushRemoteHandlers();\n    }\n};\n\n/**\n * Export individual logging methods with export capabilities\n */\nexport const debug = (...args: any[]) => exportLogger.debug(...args);\nexport const info = (...args: any[]) => exportLogger.info(...args);\nexport const warn = (...args: any[]) => exportLogger.warn(...args);\nexport const error = (...args: any[]) => exportLogger.error(...args);\nexport const success = (...args: any[]) => exportLogger.success(...args);\nexport const critical = (...args: any[]) => exportLogger.critical(...args);\nexport const trace = (...args: any[]) => exportLogger.trace(...args);\nexport const table = (data: any, columns?: string[]) => exportLogger.table(data, columns);\nexport const group = (label: string, collapsed?: boolean) => exportLogger.group(label, collapsed);\nexport const groupEnd = () => exportLogger.groupEnd();\nexport const time = (label: string) => exportLogger.time(label);\nexport const timeEnd = (label: string) => exportLogger.timeEnd(label);\nexport const setGlobalPrefix = (prefix: string) => exportLogger.setGlobalPrefix(prefix);\nexport const scope = (prefix: string) => exportLogger.scope(prefix);\nexport const setVerbosity = (level: Verbosity) => exportLogger.setVerbosity(level);\nexport const addHandler = (handler: ILogHandler) => exportLogger.addHandler(handler);\n\n/**\n * Export functionality\n */\nexport const exportLogs = async (format: 'csv' | 'json' | 'xml', options?: any) => \n    await exportLogger.exportLogs(format, options);\nexport const getLogs = () => exportLogger.getLogs();\nexport const clearLogs = () => exportLogger.clearLogs();\nexport const getLogStats = () => exportLogger.getLogStats();\n\n/**\n * Remote logging functionality\n */\nexport const addRemoteHandler = (endpoint: string, apiKey?: string) => \n    exportLogger.addRemoteHandler(endpoint, apiKey);\nexport const clearRemoteHandlers = () => exportLogger.clearRemoteHandlers();\nexport const flushRemoteHandlers = async () => await exportLogger.flushRemoteHandlers();\n\n// Export the singleton as default\nexport default exportLogger;\n\n// Re-export handlers\nexport { ExportLogHandler, RemoteLogHandler } from './handlers/index.js';\n\n// Re-export types\nexport type { ILogHandler } from './types/index.js';"],"names":["ExportLogger","Logger","exportLogHandler","remoteHandlers","constructor","config","super","bufferSize","this","ExportLogHandler","addHandler","exportLogs","format","options","Error","JSON","stringify","getLogs","clearLogs","getLogStats","addRemoteHandler","endpoint","apiKey","remoteHandler","RemoteLogHandler","push","clearRemoteHandlers","allHandlers","getHandlers","forEach","index","indexOf","splice","flushRemoteHandlers","flushPromises","map","handler","Promise","resolve","all","exportLogger","exportUtils","async","getStats","clear","remoteUtils","addEndpoint","url","clearEndpoints","flush","args","critical","debug","error","label","collapsed","group","groupEnd","info","prefix","scope","setGlobalPrefix","level","setVerbosity","success","data","columns","table","time","timeE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