Possible Duplicate:
Intercept calls to console.log in Chrome
Can I extend the console object (for rerouting the logging) in javascript?
When my JS app writes to the console.log, I want to capture that log message so that I can AJAX that log output to the server. How do I do that?
The code that writes to the log is from external services, which is why I can’t just ajax it directly.
You can hijack JavaScript functions in the following manner:
oldLog(for maintainability reasons).messageto your server.applyis used so we can invoke it onconsoleusing the original arguments. Simply callingoldLog(message)would fail becauselogdepends on its association withconsole.Update Per zzzzBov’s comment below, in IE9
console.logisn’t actually a function sooldLog.applywould fail. See console.log.apply not working in IE9 for more details.