Is there a way to fake the calling file in the Firebug console?

Note. Firebug is a Firebug extension and / or Webkit developer tool.

With fake calling file, I mean the link on the right side of the console output file, pointing to the place where the output function is called (for example, console.log).

This becomes a problem when you have a unified error message handler, etc., so all calls to console.log come from the same file and linenumber.

Is there any way to fake this information? Or bake such a link (pointing to the line number) in the firebug console log (if you have a stack)? Just by adding the file name and line number to the end of any log, add noise to the console output, making it dirty.

+4
source share
3 answers

Most modern browsers define the console.log function. How about instead of writing your own error handler, you go ahead and call console.log wherever there is an error. Then for browsers that do not define console.log, you can define it yourself, using whatever you want. For example, if you want to warn about an error in IE (or FF without firebug installed, etc.), you can use this code:

<html> <head> <title>Test</title> </head> <body> <button onclick="throwError()"> Throw Error</button> <script type="text/javascript"> function throwError() { console.log("error here!"); } if (!window.console) { window.console = { log: function(e) { alert(e); } }; } //Added in EDIT: in production add these lines below to overwrite browser console.log function window.console.log = function(e) { alert("production alert: " + e); //or whatever custom error logging you want }; </script> </body> </html> 

You can add whatever you want to the console object. I tested this in IE8 and Firefox, and I'm sure you can make this idea work for any set of browsers that you support.

EDIT: Looks like you can also overwrite the default console.log function in Firefox, Safari, and Chrome. Just reassign the console item's log item to a new function that does everything you want during production.

+2
source

Taking a brief trawl on firebug forums seems to imply that he (sometimes?) Looks at the exception to determine what the line number is .

Thus, you can well fake it this way by a reasonable massage.

0
source

With Firebug it is possible to show the call stack next to the errors. Click the down arrow next to the name of the console tab to see and activate it. This causes the plus sign to appear to the left of the message, which shows the stack. This may bring you closer to the code that caused the error.

If you also need to log errors using console.error () to use this. (not sure how compatible this is with chrome though)

0
source

All Articles