Skip to content

Instantly share code, notes, and snippets.

@jonathanborges
Created April 25, 2018 19:52
Show Gist options
  • Save jonathanborges/060fc1b17fbd05e89aa8113c9c8d2224 to your computer and use it in GitHub Desktop.
Save jonathanborges/060fc1b17fbd05e89aa8113c9c8d2224 to your computer and use it in GitHub Desktop.
const ms = require('ms');
const c = require('colors');
class Debugger {
debug(description) {
let prevTime = this.prevTime;
let curr = +new Date();
let milliseconds = curr - (prevTime || curr);
this.prevTime = curr;
let formatedMs = ms(milliseconds);
let outputAnsi = c.bold.green(description) + ' ' + c.green(formatedMs) + "\n";
process.stderr.write(outputAnsi);
console.log("%c" + description + " %c" + formatedMs, 'font-weight:bold;color:green', 'color:green');
}
}
function debug(description) {
let d = new Debugger();
d.debug.call(this, description);
}
module.exports = debug;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment