Getting a firebug console to display different line numbers

I wrapped the firebugs console.log calls in a logging function (which checks for the presence of the console along with other flags)

eg:

Log(string) { if (console && DEBUG) console.log(string); } 

my problem is that the firebug console shows the line number of the console.log function call, not the Log function call.

Is there a way to change the display of strings in Firebug?

+4
source share
4 answers

Firebug does not allow you to change the line number on the console using code.

+2
source

console.trace () will provide you with a call stack.

See http://getfirebug.com/logging for more details.

+1
source

I took a slightly different approach and just defined a property that sets the __stack__ variable by intentionally throwing an error, from this we can get the file name, line number (and many others, such as callers and their line numbers, if you choose to implement them) .

Instead of setting up the log function, I also set it as a variable, but registering when I set it. This will be the location where the LOG is installed, not where it was defined.

Its as simple as LOG = "my message." You can then use it later as a variable to get the location of your last debug using alert(LOG)

 /*@const*/ //for closure-compiler DEBUG=2 // 0=off, 1=msg:file:line:column, 2=msg:stack-trace if(DEBUG){ /*@const @constructor*/ Object.defineProperty(window,'__stack__',{get:function(){ try{_ფ_()}catch(e){return e.stack.split(":")} }}) /*@const @constructor*/ Object.defineProperty(window,'__file__',{get:function(){ var s=__stack__,l=s.length return (isNaN(s[l-2]))?s[l-2]:s[l-3] }}) /*@const @constructor*/ Object.defineProperty(window,'__line__',{get:function(){ var s=__stack__,l=s.length return (isNaN(s[l-2]))?s[l-1]:s[l-2] }}) /*@const @constructor*/ Object.defineProperty(window,'__col__',{get:function(){ var s=__stack__,l=s.length return (isNaN(s[l-2]))?"NA":s[l-1] }}) /*@const @constructor*/ Object.defineProperty(window,'LOG',{ get:function(){return out}, set:function(msg){if(DEBUG>1)out=msg+"\t-\t"+__stack__ else out=msg+" in file:"+__file__+" @ Line:"+__line__+", Column:"+__col__ console.log(out)} }) }//end if(DEBUG) 
0
source

There seems to be no way to do this, so I used console.group

 console.group(file +' (line '+ line +')'); console.log(data); console.groupEnd(); 
0
source

All Articles