import { Platform } from 'react-native'; export default class FWLoggerUtil { static enabled: boolean = false; private static warnedMessages: Set = new Set(); /** * Emits a developer-facing warning (independent of `enabled`) once per `id` for * the lifetime of the app, for prop misuse that should not be silently ignored. */ static warnOnce(id: string, message: string) { if (FWLoggerUtil.warnedMessages.has(id)) { return; } FWLoggerUtil.warnedMessages.add(id); console.warn('[react-native-firework-sdk]', `[${Platform.OS}]`, message); } static log(message: string) { if (FWLoggerUtil.enabled && process.env.NODE_ENV === 'development') { const currentDate = new Date(); console.log( '[react-native-firework-sdk]', `[${Platform.OS}]`, `${message} ${FWLoggerUtil.toISOString(currentDate)}` ); } } static logNativeMessage(nativeMessage: string) { if (FWLoggerUtil.enabled && process.env.NODE_ENV === 'development') { console.log( '[react-native-firework-sdk] [native]', `[${Platform.OS}]`, nativeMessage ); } } private static toISOString(date: Date): string { let timezoneOffset = -date.getTimezoneOffset(); let timezoneSymbol = timezoneOffset >= 0 ? '+' : '-'; let timezoneHours = Math.floor(Math.abs(timezoneOffset) / 60) .toString() .padStart(2, '0'); let timezoneMinutes = (Math.abs(timezoneOffset) % 60) .toString() .padStart(2, '0'); let timezoneString = `${timezoneSymbol}${timezoneHours}:${timezoneMinutes}`; let year = date.getFullYear().toString(); let month = (date.getMonth() + 1).toString().padStart(2, '0'); let day = date.getDate().toString().padStart(2, '0'); let hours = date.getHours().toString().padStart(2, '0'); let minutes = date.getMinutes().toString().padStart(2, '0'); let seconds = date.getSeconds().toString().padStart(2, '0'); let milliseconds = date.getMilliseconds().toString().padStart(3, '0'); return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}${timezoneString}`; } }