Extending console.log without affecting log line

I would like to extend the ‘console.log’ function to add additional information to its output – but I dont want to affect the script name/line number information generated by the browser in the console window. See how if I create my own implementation, I get useless trace information, should I want to locate that region of code… (they all link to the log implementation, not the actual script that caused the log message)

enter image description here

Basically, my application is a very pluggable infrastructure, were any log output may occur within any number of frames.
As such, I want every log message to include a special unique identifier at the beginning of the log message.

I have tried replacing the console.log method with my own, but chrome complains with
Uncaught TypeError: Illegal invocation

this is how I override it

var orig = console.log;
console.log = function( message )
    orig( (window == top ? '[root]' : '[' + window.name + ']') + ': ' + message );

Any ideas?

Note: After fixing the ‘illegal invocation’ problem, it seems the filename/linenumber is still ‘polluted’ by the override…

It looks like the general answer is – NO – despite some confusing goose chases, the desired functionality is NOT achievable in the current versions of browsers.

133 thoughts on “Extending console.log without affecting log line”

  1. Undeniably believe that which you said. Your favorite reason appeared to be on the internet the simplest thing to be aware
    of. I say to you, I definitely get annoyed while people think about worries that
    they plainly don’t know about. You managed to hit the nail upon the top as well as defined out the whole thing without
    having side effect , people could take a signal. Will likely be back to get more.
    Thanks http://cleckleyfloors.com/

  2. We stumbled over here by a different website and thought I should check things out. I like what I see so now i’m following you. Look forward to finding out about your web page repeatedly.