UNPKG

japp

Version:

An npm package to compare images and snapshots

51 lines (48 loc) 1.19 kB
var fs = require("fs"); var path = require("path"); var timers = {}; module.exports = { writeStream: false, warn: function (msg) { var str = "WARNING:: " + msg + "\n"; console.log(str); this.writeStream && fs.write(this.writeStream, str); }, info: function (msg) { var str = "INFO:: " + msg + "\n"; console.log(str); this.writeStream && fs.write(this.writeStream, str); }, error: function (msg) { var str = "ERROR:: " + msg + "\n"; console.log(str); this.writeStream && fs.write(this.writeStream, str); }, startTime: function (msg) { if (timers[msg]) { this.warn("Timer has already been started for " + msg); } else { timers[msg] = new Date(); } }, endTime: function (msg) { var totalTime = new Date() - timers[msg]; console.log("TIME:: " + msg + ": " + totalTime); }, setWriteStream: function (fileName) { if (this.writeStream) { this.closeWriteStream(); } this.writeStream = fs.openSync(path.join(process.cwd(), fileName), 'w'); }, closeWriteStream: function () { if (this.writeStream) { fs.closeSync(this.writeStream); this.writeStream = false; } } };