Skip to content

Instantly share code, notes, and snippets.

@magnli10 magnli10/logstore
Created Apr 25, 2016

Embed
What would you like to do?
Draft of logging lib for comscore maelstrom
'use strict';
var store = {};
module.exports.get = function get() {
var items = {};
Array.prototype.slice.call(arguments)
.filter(function (arg){
return store[arg];
})
.map(function(arg){
//Returning literal set the key name to "arg", hence this
items[arg] = store[arg];
});
return items;
};
module.exports.increment = function(key) {
if(typeof store[key] === 'undefined'){
return store[key] = 1;
}
var val = Number(store[key]);
if(val === store[key] && val%1 === 0){
return store[key] = ++val;
}
log.warn("Failed to increment %s. It is not an integer.", store[key])
return 0;
};
module.exports.append = function(key, value) {
if(typeof store[key] === 'undefined'){
return store[key] = [value];
}
if(Object.prototype.toString.call(store[key]) === '[object Array]'){
return store[key] = store[key].concat([value]);
}
log.warn("Failed to append %s. It is not an array.", store[key]);
return null;
};
module.exports.set = function(key, value){
return store[key] = value;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.