I have a goal of creating a logging proxy that adds a specific prefix to each log statement.
What I aim to accomplish is:
customDebug("xxx","yyy");
which translates to:
console.debug("prefix","xxx","yyy");
My attempt at implementing this is as follows:
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 );
},
However, the error
Uncaught TypeError: Illegal invocation
is raised indicating that native code cannot be invoked using apply/call
, even with an undefined context.
If anyone has suggestions on how to achieve this, please let me know.
As a workaround, I can use console.debug(argArray);
which is not ideal since it logs an array instead of individual arguments.