UNPKG

@mustafakarali/react-native-audio-stream

Version:

React Native Audio Stream - High-performance audio streaming for React Native

140 lines (133 loc) 3.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.logger = exports.Logger = void 0; var _types = require("./types"); // TypeScript için console.time ve console.timeEnd fonksiyonlarını tanımla class Logger { logLevel = _types.LogLevel.WARNING; tag = 'AudioStream'; timeLabels = new Map(); constructor() {} static getInstance() { if (!Logger.instance) { Logger.instance = new Logger(); } return Logger.instance; } setLogLevel(level) { this.logLevel = level; } setTag(tag) { this.tag = tag; } shouldLog(level) { return level <= this.logLevel; } formatMessage(level, message, ...args) { const timestamp = new Date().toISOString(); const formattedArgs = args.length > 0 ? ' ' + JSON.stringify(args) : ''; return `[${timestamp}] [${this.tag}] [${level}] ${message}${formattedArgs}`; } error(message, ...args) { if (this.shouldLog(_types.LogLevel.ERROR)) { console.error(this.formatMessage('ERROR', message, ...args)); } } warn(message, ...args) { if (this.shouldLog(_types.LogLevel.WARNING)) { console.warn(this.formatMessage('WARN', message, ...args)); } } info(message, ...args) { if (this.shouldLog(_types.LogLevel.INFO)) { console.info(this.formatMessage('INFO', message, ...args)); } } debug(message, ...args) { if (this.shouldLog(_types.LogLevel.DEBUG)) { console.log(this.formatMessage('DEBUG', message, ...args)); } } verbose(message, ...args) { if (this.shouldLog(_types.LogLevel.VERBOSE)) { console.log(this.formatMessage('VERBOSE', message, ...args)); } } // Performance logging time(label) { if (this.shouldLog(_types.LogLevel.DEBUG)) { const tagLabel = `[${this.tag}] ${label}`; if (typeof console.time === 'function') { console.time(tagLabel); } else { this.timeLabels.set(tagLabel, Date.now()); this.debug(`Timer started: ${tagLabel}`); } } } timeEnd(label) { if (this.shouldLog(_types.LogLevel.DEBUG)) { const tagLabel = `[${this.tag}] ${label}`; if (typeof console.timeEnd === 'function') { console.timeEnd(tagLabel); } else { const start = this.timeLabels.get(tagLabel); if (start) { const duration = Date.now() - start; this.debug(`Timer ended: ${tagLabel} - ${duration}ms`); this.timeLabels.delete(tagLabel); } else { this.debug(`Timer not found: ${tagLabel}`); } } } } // Network logging logNetworkRequest(url, headers) { if (this.shouldLog(_types.LogLevel.DEBUG)) { this.debug('Network Request', { url, headers }); } } logNetworkResponse(url, status, duration) { if (this.shouldLog(_types.LogLevel.DEBUG)) { this.debug('Network Response', { url, status, duration: `${duration}ms` }); } } // Buffer logging logBufferStatus(bufferedPercentage, bufferHealth) { if (this.shouldLog(_types.LogLevel.VERBOSE)) { this.verbose('Buffer Status', { bufferedPercentage: `${bufferedPercentage}%`, bufferHealth: `${bufferHealth}%` }); } } // Playback logging logPlaybackEvent(event, details) { if (this.shouldLog(_types.LogLevel.INFO)) { this.info(`Playback Event: ${event}`, details); } } // Error logging with stack trace logError(error, context) { if (this.shouldLog(_types.LogLevel.ERROR)) { const errorMessage = error instanceof Error ? error.message : error; const stack = error instanceof Error ? error.stack : undefined; this.error(`${context ? `[${context}] ` : ''}${errorMessage}`, { stack }); } } } exports.Logger = Logger; const logger = exports.logger = Logger.getInstance(); //# sourceMappingURL=logger.js.map