As I interact with my AJAX based application at RUNTIME I’d like the console to spit out all the functions it’s calling. (so no stack trace, or breakpoints, or profiling or anything)
So for example, let’s say I pressed a button on the page. I’d like for it to return all the functions it
went through when that happened:
So I’d see in the console something like (when I pressed a button):
1. button1Clicked();
2. calculating();
3. printingResults();
Which basically means that button1Clicked() called calculating() which called printingResults()
Is there a utility, or plugin, browser, or maybe some way in the language to do this? I’m using google chrome, btw.
p.s and NO I do not want to go through each function and add a "console.log("inside function X")" b/c that’s too much work
p.p.s as an added bonus I’d like to see the arguments passed into the functions too, but maybe that’s pushing it. :>
I can’t think of a great way to intercept all function calls globally to insert logging (though there is a decent workaround in the update section below).
Instead, how about only adding logging to functions in a certain namespace that you care about? You can do this with the following setup code:
Then, for whatever namespaceObject you want to add logging to, you just call:
Here’s a fiddle to see it in action.
UPDATE
Note that you can call
functionLogger.addLoggingToNamespace(window);to add logging to all global functions at the time of the call. Also, if you really want, you can traverse the tree to find any functions and update them accordingly. The one downfall of this method is that it only works on functions that exist at the time. Thus, it’s still not the greatest solution, but it’s a LOT less work than adding logging statements by hand 🙂