UNPKG

@tsparticles/engine

Version:

Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.

48 lines (47 loc) • 1.46 kB
const errorPrefix = "tsParticles - Error", codedErrorPattern = /^\[tsParticles Error (TSP-\d+)\]\s*/, fullMatchIndex = 0, codeIndex = 1; const wrap = (fn) => (...args) => { fn(...args); }, _logger = { debug: wrap(console.debug), error: (message, ...optionalParams) => { if (typeof message === "string") { const match = codedErrorPattern.exec(message); if (match?.[codeIndex]) { console.error(`tsParticles - ${match[codeIndex]} - ${message.slice(match[fullMatchIndex].length)}`, ...optionalParams); return; } } console.error(`${errorPrefix} - ${message}`, ...optionalParams); }, info: wrap(console.info), log: wrap(console.log), trace: wrap(console.trace), verbose: wrap(console.log), warning: wrap(console.warn), }; export function setLogger(logger) { if (logger.debug) { _logger.debug = wrap(logger.debug); } if (logger.error) { _logger.error = wrap(logger.error); } if (logger.info) { _logger.info = wrap(logger.info); } if (logger.log) { _logger.log = wrap(logger.log); } if (logger.trace) { _logger.trace = wrap(logger.trace); } if (logger.verbose) { _logger.verbose = wrap(logger.verbose); } if (logger.warning) { _logger.warning = wrap(logger.warning); } } export function getLogger() { return _logger; }