/**
 * Centralized logging service for dashboard visibility
 */
const MAX_LOG_ENTRIES = 200;
const logBuffer = [];
const listeners = [];
/**
 * Add a log entry
 */
export function addLog(level, message, data) {
    const entry = {
        timestamp: new Date().toISOString(),
        level,
        message,
        data,
    };
    logBuffer.push(entry);
    if (logBuffer.length > MAX_LOG_ENTRIES) {
        logBuffer.shift();
    }
    // Notify all listeners
    for (const listener of listeners) {
        try {
            listener(entry);
        }
        catch {
            // Ignore listener errors
        }
    }
}
/**
 * Get all log entries
 */
export function getLogs() {
    return [...logBuffer];
}
/**
 * Get logs filtered by level
 */
export function getLogsByLevel(level) {
    return logBuffer.filter(log => log.level === level);
}
/**
 * Get error logs only
 */
export function getErrorLogs() {
    return logBuffer.filter(log => log.level === 'error' || log.level === 'warn');
}
/**
 * Subscribe to new log entries
 */
export function onLog(callback) {
    listeners.push(callback);
    return () => {
        const index = listeners.indexOf(callback);
        if (index !== -1) {
            listeners.splice(index, 1);
        }
    };
}
/**
 * Clear all logs
 */
export function clearLogs() {
    logBuffer.length = 0;
}
// Convenience methods
export const logInfo = (msg, data) => addLog('info', msg, data);
export const logWarn = (msg, data) => addLog('warn', msg, data);
export const logError = (msg, data) => addLog('error', msg, data);
export const logDebug = (msg, data) => addLog('debug', msg, data);
//# sourceMappingURL=logBuffer.js.map