I would like to log the user_id of the person making a request and the method name of every method called for a javascript class. For example:
35 - log_in
35 -
The answer is essentially correct, but here's how to avoid infinite recursion
Javascript
(function () {
var oldCall = Function.prototype.call;
var newCall = function(self) {
Function.prototype.call = oldCall;
console.log('Function called:', this.name);
var args = Array.prototype.slice.call(arguments, 1);
var res = this.apply(self, args);
Function.prototype.call = newCall;
return res
}
Function.prototype.call = newCall;
})();
Coffeescript
do ->
oldCall = Function::call
newCall = (self) ->
Function::call = oldCall
console.log "Function called: #{this.name}"
args = Array.prototype.slice.call arguments, 1
res = this.apply self, args
Function::call = newCall
res
Function::call = newCall