I am trying to write a generic log function that will accept string and object type of arguments of variable length and print them with some metadata related to the modules and sub modules. But I can't figure out a way print all the arguments together. Currently I am doing this.
// MODULE_NAME is different for every module of my project, so
// that I know which module the log belongs to.
function myLogger() {
for (var i = 0; i < arguments.length; i++) {
console.log(MODULE_NAME, ":", arguments[i]);
}
}
I am looking for a better way to do it which will work for following examples.
// MODULE_NAME = "TEST"
myLogger("error");
myLogger("error", err, ", result", res);
myLogger("hello", "world");
Output of the above calls should be
TEST : error
TEST : error {obj}, result {obj}
TEST : hello world
jointo join them.