I'm trying to create a logging proxy where each log statement has a prefix.
What I want is to do:
customDebug("xxx","yyy");
and under the wood it will do:
console.debug("prefix","xxx","yyy");
I've tried to implement it this way:
prefixLogArguments: function(arg) {
var array = _.toArray(arg);
array.unshift( this.getPrefix() );
return array;
},
customDebug: function() {
var argArray = this.prefixLogArguments(arguments);
console.debug.apply(undefined, argArray );
},
It says Uncaught TypeError: Illegal invocation
because it seems we can't invoke native code with apply/call
, even with an undefined context.
Can someone tell me how to achieve this?
I can do console.debug(argArray);
it's not so bad but it does not produce the same result as it logs an array instead of logging an argument list.