sync/lib/counters.js

22 lines
434 B
JavaScript
Raw Normal View History

2015-09-18 06:29:32 +00:00
var Logger = require('./logger');
var counterLog = new Logger.Logger('counters.log');
var counters = {};
exports.add = function (counter, value) {
if (!value) {
value = 1;
}
if (!counters.hasOwnProperty(counter)) {
counters[counter] = value;
} else {
counters[counter] += value;
}
};
setInterval(function () {
counterLog.log(JSON.stringify(counters));
counters = {};
}, 60000);