fn-buffer
Make your function buffer calls till you flush.
Useful to make Backtrace logging.
Install
npm install fn-buffer
API
new BufferedFunction(fn, opts)
fn <function>(required) The function to buffer calls of
opts [number|object] Options or capacity
opts.capacity [number=10] Capacity of the ring-buffer of the calls
opts.flush [boolean|number=capacity] Auto-flush when buffer gets full
opts.reverse [boolean] Reverse the order of buffer calls
Example
import BufferedFunction from 'fn-buffer'
const bufferedLog = new BufferedFunction(console.log);
bufferedLog('a')
bufferedLog('b')
bufferedLog('c')
bufferedLog('d')
bufferedLog('e')
bufferedLog.flush();
Backtrace logging
This can be used to create backtrace-logging:
import BufferedFunction from 'fn-buffer'
export const debug = BufferedFunction(console.debug, { flush: false })
process.on('uncaughtExceptionMonitor', debug.flush)
This debug function will only log to console in the event of an uncaughtException.
See backtrace-logging for a module that does exactly this.