UNPKG

log-mate

Version:

log-mate makes logging effortless & powerful—log to console, files, databases, or cloud with structured logs, encryption, real-time streaming, and auto-rotation. It’s plug & play, supports multi-transport logging, and boosts performance with async, lazy l

16 lines (13 loc) 481 B
const _ = require("lodash"); function retry(logFunc, attempts = 3, delay = 1000) { return async (level, message) => { const wrapped = _.attempt(() => logFunc(level, message)); if (_.isError(wrapped)) { for (let i = 0; i < attempts; i++) { await new Promise(res => setTimeout(res, delay)); if (!_.attempt(() => logFunc(level, message))) break; } } }; } module.exports = retry;